From 4ccc03fbac0d0423684d95f5296c54b2fb8150f4 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Wed, 4 Jul 2018 18:53:21 +0200 Subject: [PATCH 1/2] CMake: properly check for variables Checking them for being defined would get the user intention wrong if they are passed as -DDISABLE_STATIC=Off as that would still count as being defined. Just check for the variable, which has the desired effect. An unset variable is always false. Since these flags are options now the variables are always set, so one cannot disable this features anymore otherwise. --- CMakeLists.txt | 10 +++++----- sq/CMakeLists.txt | 16 ++++++++-------- sqstdlib/CMakeLists.txt | 14 +++++++------- squirrel/CMakeLists.txt | 14 +++++++------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33d4407..f7d407b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,12 +43,12 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8) add_definitions(-D_SQ64) endif() -if(NOT DEFINED SQ_DISABLE_INSTALLER) - if(NOT DEFINED INSTALL_BIN_DIR) +if(NOT SQ_DISABLE_INSTALLER) + if(NOT INSTALL_BIN_DIR) set(INSTALL_BIN_DIR bin) endif() - if(NOT DEFINED INSTALL_LIB_DIR) + if(NOT INSTALL_LIB_DIR) set(INSTALL_LIB_DIR lib) endif() endif() @@ -57,11 +57,11 @@ add_subdirectory(squirrel) add_subdirectory(sqstdlib) add_subdirectory(sq) -if(NOT WIN32 AND NOT DEFINED DISABLE_DYNAMIC) +if(NOT WIN32 AND NOT DISABLE_DYNAMIC) set_target_properties(squirrel sqstdlib PROPERTIES SOVERSION 0 VERSION 0.0.0) endif() -if(DEFINED INSTALL_INC_DIR) +if(INSTALL_INC_DIR) set(SQ_PUB_HEADERS include/sqconfig.h include/sqstdaux.h include/sqstdblob.h diff --git a/sq/CMakeLists.txt b/sq/CMakeLists.txt index daadb2d..d7154ef 100644 --- a/sq/CMakeLists.txt +++ b/sq/CMakeLists.txt @@ -1,34 +1,34 @@ -if(NOT DEFINED DISABLE_DYNAMIC) +if(NOT DISABLE_DYNAMIC) if(CMAKE_COMPILER_IS_GNUCXX) set_source_files_properties(sq.c PROPERTIES COMPILE_FLAGS -std=c99) endif() add_executable(sq sq.c) set_target_properties(sq PROPERTIES LINKER_LANGUAGE C) target_link_libraries(sq squirrel sqstdlib) - if(NOT DEFINED SQ_DISABLE_INSTALLER) + if(NOT SQ_DISABLE_INSTALLER) install(TARGETS sq RUNTIME DESTINATION ${INSTALL_BIN_DIR}) endif() endif() -if(NOT DEFINED DISABLE_STATIC) +if(NOT DISABLE_STATIC) add_executable(sq_static sq.c) set_target_properties(sq_static PROPERTIES LINKER_LANGUAGE C) target_link_libraries(sq_static squirrel_static sqstdlib_static) - if(NOT DEFINED SQ_DISABLE_INSTALLER) + if(NOT SQ_DISABLE_INSTALLER) install(TARGETS sq_static RUNTIME DESTINATION ${INSTALL_BIN_DIR}) endif() endif() -if(DEFINED LONG_OUTPUT_NAMES) - if(NOT DEFINED DISABLE_DYNAMIC) +if(LONG_OUTPUT_NAMES) + if(NOT DISABLE_DYNAMIC) set_target_properties(sq PROPERTIES OUTPUT_NAME squirrel3) endif() - if(NOT DEFINED DISABLE_STATIC) + if(NOT DISABLE_STATIC) set_target_properties(sq_static PROPERTIES OUTPUT_NAME squirrel3_static) endif() endif() -if(CMAKE_COMPILER_IS_GNUCXX AND (NOT DEFINED DISABLE_STATIC)) +if(CMAKE_COMPILER_IS_GNUCXX AND NOT DISABLE_STATIC) set_target_properties(sq_static PROPERTIES COMPILE_FLAGS "-static -Wl,-static") endif() diff --git a/sqstdlib/CMakeLists.txt b/sqstdlib/CMakeLists.txt index 86ad721..00cc822 100644 --- a/sqstdlib/CMakeLists.txt +++ b/sqstdlib/CMakeLists.txt @@ -7,29 +7,29 @@ set(SQSTDLIB_SRC sqstdaux.cpp sqstdstring.cpp sqstdsystem.cpp) -if(NOT DEFINED DISABLE_DYNAMIC) +if(NOT DISABLE_DYNAMIC) add_library(sqstdlib SHARED ${SQSTDLIB_SRC}) target_link_libraries(sqstdlib squirrel) - if(NOT DEFINED SQ_DISABLE_INSTALLER) + if(NOT SQ_DISABLE_INSTALLER) install(TARGETS sqstdlib RUNTIME DESTINATION ${INSTALL_BIN_DIR} LIBRARY DESTINATION ${INSTALL_LIB_DIR} ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) endif() endif() -if(NOT DEFINED DISABLE_STATIC) +if(NOT DISABLE_STATIC) add_library(sqstdlib_static STATIC ${SQSTDLIB_SRC}) - if(NOT DEFINED SQ_DISABLE_INSTALLER) + if(NOT SQ_DISABLE_INSTALLER) install(TARGETS sqstdlib_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) endif() endif() -if(DEFINED LONG_OUTPUT_NAMES) - if(NOT DEFINED DISABLE_DYNAMIC) +if(LONG_OUTPUT_NAMES) + if(NOT DISABLE_DYNAMIC) set_target_properties(sqstdlib PROPERTIES OUTPUT_NAME sqstdlib3) endif() - if(NOT DEFINED DISABLE_STATIC) + if(NOT DISABLE_STATIC) set_target_properties(sqstdlib_static PROPERTIES OUTPUT_NAME sqstdlib3_static) endif() endif() diff --git a/squirrel/CMakeLists.txt b/squirrel/CMakeLists.txt index 8ba67fb..dc2bbb0 100644 --- a/squirrel/CMakeLists.txt +++ b/squirrel/CMakeLists.txt @@ -11,28 +11,28 @@ set(SQUIRREL_SRC sqapi.cpp sqtable.cpp sqvm.cpp) -if(NOT DEFINED DISABLE_DYNAMIC) +if(NOT DISABLE_DYNAMIC) add_library(squirrel SHARED ${SQUIRREL_SRC}) - if(NOT DEFINED SQ_DISABLE_INSTALLER) + if(NOT SQ_DISABLE_INSTALLER) install(TARGETS squirrel RUNTIME DESTINATION ${INSTALL_BIN_DIR} LIBRARY DESTINATION ${INSTALL_LIB_DIR} ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) endif() endif() -if(NOT DEFINED DISABLE_STATIC) +if(NOT DISABLE_STATIC) add_library(squirrel_static STATIC ${SQUIRREL_SRC}) - if(NOT DEFINED SQ_DISABLE_INSTALLER) + if(NOT SQ_DISABLE_INSTALLER) install(TARGETS squirrel_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR}) endif() endif() -if(DEFINED LONG_OUTPUT_NAMES) - if(NOT DEFINED DISABLE_DYNAMIC) +if(LONG_OUTPUT_NAMES) + if(NOT DISABLE_DYNAMIC) set_target_properties(squirrel PROPERTIES OUTPUT_NAME squirrel3) endif() - if(NOT DEFINED DISABLE_STATIC) + if(NOT DISABLE_STATIC) set_target_properties(squirrel_static PROPERTIES OUTPUT_NAME squirrel3_static) endif() endif() From 73692881c1b7fc4618f348e355d5464f6997cdc9 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Wed, 4 Jul 2018 18:57:05 +0200 Subject: [PATCH 2/2] CMake: properly set default build type --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7d407b..28191b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,9 @@ option(DISABLE_STATIC "Avoid building/installing static libraries.") option(LONG_OUTPUT_NAMES "Use longer names for binaries and libraries: squirrel3 (not sq).") set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}" CACHE PATH "") -set(CMAKE_BUILD_TYPE "Release" CACHE STRING "") +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") +endif () project(squirrel C CXX)