refactor(src/CMakeLists.txt): simplify conditions in if

There are many places where we do not need 'MATCHES "ON"' or 'MATCHES
"OFF"'. Reference: http://www.cmake.org/cmake/help/v3.0/command/if.html

~~~
if(<constant>)

True if the constant is 1, ON, YES, TRUE, Y, or a non-zero number. False
if the constant is 0, OFF, NO, FALSE, N, IGNORE, NOTFOUND, the empty
string, or ends in the suffix -NOTFOUND. Named boolean constants are
case-insensitive. If the argument is not one of these constants, it is
treated as a variable.
~~~
This commit is contained in:
Soonho Kong 2015-04-30 09:51:05 -04:00
parent c19ec664b8
commit 7bae895c23

View file

@ -70,23 +70,23 @@ if("${CYGWIN}" EQUAL "1")
set(LEAN_EXTRA_CXX_FLAGS "${LEAN_EXTRA_CXX_FLAGS} -D LEAN_CYGWIN")
endif()
if("${MULTI_THREAD}" MATCHES "OFF")
if(NOT MULTI_THREAD)
message(STATUS "Disabled multi-thread support, it will not be safe to run multiple threads in parallel")
else()
set(LEAN_EXTRA_CXX_FLAGS "${LEAN_EXTRA_CXX_FLAGS} -D LEAN_MULTI_THREAD")
endif()
if("${CACHE_EXPRS}" MATCHES "ON")
if(CACHE_EXPRS)
message(STATUS "Lean expression caching enabled (aka partial hashconsing)")
set(LEAN_EXTRA_CXX_FLAGS "${LEAN_EXTRA_CXX_FLAGS} -D LEAN_CACHE_EXPRS")
endif()
if(("${CONSERVE_MEMORY}" MATCHES "ON") AND ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU"))
if(CONSERVE_MEMORY AND ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU"))
message(STATUS "Using compilation flags for minimizing the amount of memory used by gcc")
set(LEAN_EXTRA_CXX_FLAGS "${LEAN_EXTRA_CXX_FLAGS} --param ggc-min-heapsize=32768 --param ggc-min-expand=20")
endif()
if("${STATIC}" MATCHES "ON")
if(STATIC)
message(STATUS "Creating a static executable")
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LEAN_EXTRA_LINKER_FLAGS "${LEAN_EXTRA_LINKER_FLAGS} -Wl,--whole-archive -lpthread -Wl,--no-whole-archive")
@ -115,13 +115,13 @@ set(CMAKE_CXX_FLAGS_EMSCRIPTEN "-Oz -s DISABLE_EXCEPTION_CATCHING=0 -D LEAN_
include(CheckIncludeFileCXX)
check_include_file_cxx("unistd.h" HAVE_UNISTD)
if ("${IGNORE_SORRY}" MATCHES "ON")
if (IGNORE_SORRY)
message(STATUS "IGNORE_SORRY is ON, Lean will not report when 'sorry' is used directly or indirectly")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D LEAN_IGNORE_SORRY")
endif()
# SPLIT_STACK
if ("${SPLIT_STACK}" MATCHES "ON")
if (SPLIT_STACK)
if ((${CMAKE_SYSTEM_NAME} MATCHES "Linux") AND ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU"))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsplit-stack -D LEAN_USE_SPLIT_STACK")
message(STATUS "Using split-stacks")
@ -131,7 +131,7 @@ if ("${SPLIT_STACK}" MATCHES "ON")
endif()
# Test coverage
if("${TESTCOV}" MATCHES "ON")
if(TESTCOV)
include(CodeCoverage)
message(STATUS "Enable test-coverage")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -fprofile-arcs -ftest-coverage --coverage")
@ -152,14 +152,14 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(LEAN_EXTRA_LINKER_FLAGS "-stdlib=libc++")
endif ()
elseif ("${EMSCRIPTEN}" MATCHES "ON")
elseif (EMSCRIPTEN)
message(STATUS "Emscripten is detected: Make sure the wraped compiler supports C++11")
else()
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
endif ()
# BOOST
if (("${BOOST}" MATCHES "ON") AND ("${MULTI_THREAD}" MATCHES "ON"))
if (BOOST AND MULTI_THREAD)
find_package(Boost 1.54 COMPONENTS system thread atomic chrono REQUIRED)
message(STATUS "Boost library will be used to implement multi-threading support")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D LEAN_USE_BOOST")
@ -181,12 +181,12 @@ include_directories(${GMP_INCLUDE_DIR})
set(EXTRA_LIBS ${EXTRA_LIBS} ${GMP_LIBRARIES})
# TRACK_MEMORY_USAGE
if("${TRACK_MEMORY_USAGE}" MATCHES "ON")
if(TRACK_MEMORY_USAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D LEAN_TRACK_MEMORY")
endif()
# jemalloc
if("${JEMALLOC}" MATCHES "ON")
if(JEMALLOC)
find_package(Jemalloc)
if(${JEMALLOC_FOUND})
set(EXTRA_LIBS ${EXTRA_LIBS} ${JEMALLOC_LIBRARIES})
@ -199,7 +199,7 @@ endif()
# tcmalloc
if(NOT "${JEMALLOC_FOUND}")
if("${TCMALLOC}" MATCHES "ON")
if(TCMALLOC)
find_package(Tcmalloc)
if(${TCMALLOC_FOUND})
set(EXTRA_LIBS ${EXTRA_LIBS} ${TCMALLOC_LIBRARIES})
@ -214,7 +214,7 @@ if(NOT "${JEMALLOC_FOUND}")
endif()
# Readline
if("${READLINE}" MATCHES "ON")
if(READLINE)
find_package(Readline)
set(EXTRA_LIBS ${EXTRA_LIBS} ${READLINE_LIBRARY})
message(STATUS "Using GNU readline")
@ -222,17 +222,17 @@ if("${READLINE}" MATCHES "ON")
endif()
# Check malloc_usable_size
if(NOT "${EMSCRIPTEN}" AND NOT "${TCMALLOC_FOUND}" AND NOT "${JEMALLOC_FOUND}" AND "${TRACK_MEMORY_USAGE}" MATCHES "ON")
if(NOT "${EMSCRIPTEN}" AND NOT "${TCMALLOC_FOUND}" AND NOT "${JEMALLOC_FOUND}" AND TRACK_MEMORY_USAGE)
find_package(MallocUsableSize)
if("${MUS_FOUND}" MATCHES "TRUE")
if(MUS_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I ${MALLOC_DIR} -D HAS_MALLOC_USABLE_SIZE")
else()
find_package(MallocSize)
if("${MALLOCSIZE_FOUND}" MATCHES "TRUE")
if(MALLOCSIZE_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I ${MALLOC_DIR} -D HAS_MALLOCSIZE")
else()
find_package(MSize)
if("${MSIZE_FOUND}" MATCHES "TRUE")
if(MSIZE_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I ${MALLOC_DIR} -D HAS_MSIZE")
endif()
endif()
@ -247,7 +247,7 @@ if(NOT "${EMSCRIPTEN}" AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(EXTRA_LIBS ${EXTRA_LIBS} -ldl)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I ${LUA_INCLUDE_DIR}")
if ("${HAS_LUA_NEWSTATE}$" MATCHES "TRUE")
if (HAS_LUA_NEWSTATE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D LEAN_USE_LUA_NEWSTATE")
endif()
@ -339,7 +339,7 @@ set(LEAN_LIBS ${LEAN_LIBS} leanlua)
add_subdirectory(init)
set(LEAN_LIBS ${LEAN_LIBS} init)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LEAN_EXTRA_LINKER_FLAGS}")
if(("${MULTI_THREAD}" MATCHES "ON") AND (NOT (("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") AND ("${BOOST}" MATCHES "ON"))))
if(MULTI_THREAD AND (NOT (("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") AND BOOST)))
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
endif()
set(CMAKE_EXE_LINKER_FLAGS_TESTCOV "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")