Browse Source

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.
Rolf Eike Beer 7 years ago
parent
commit
4ccc03fbac
4 changed files with 27 additions and 27 deletions
  1. 5 5
      CMakeLists.txt
  2. 8 8
      sq/CMakeLists.txt
  3. 7 7
      sqstdlib/CMakeLists.txt
  4. 7 7
      squirrel/CMakeLists.txt

+ 5 - 5
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

+ 8 - 8
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()

+ 7 - 7
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()

+ 7 - 7
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()