Reputation: 11
I'm pretty new to cmake. I'm using the following:
cmake -DUSE_OLD_CODE:BOOL=FALSE
This works fine. But when I change the FALSE
to TRUE
, the compiler seems to think that USE_OLD_CODE
is a file and then complains that it cannot find it.
Below is CMakeLists.txt
cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_compile_options(-std=c++11 /W4 /wd"4127" /wd"4201" /MP)
IF(USE_OLD_CODE) add_compile_options(/D "USE_OLD_CODE") ENDIF(USE_OLD_CODE)
set( SOURCES "main.cpp" )
set (OLD_CODE_SOURCES "OldCode.cpp" )
set (NEW_CODE_SOURCES "NewCode.cpp" )
IF(USE_OLD_CODE) set (SOURCES ${SOURCES} "${OLD_CODE_SOURCES}") ELSE(USE_OLD_CODE) set (SOURCES ${SOURCES} "${NEW_CODE_SOURCES}") ENDIF(USE_OLD_CODE)
IF(WIN32) add_executable(${EXECUTABLE} WIN32 ${SOURCES}) ELSEIF(UNIX) add_executable(${EXECUTABLE} ${SOURCES}) ENDIF(WIN32)
Any ideas what I am doing wrong?
thanks
james
Upvotes: 0
Views: 819
Reputation: 69882
shouldn't it be add_compile_options("/DUSE_OLD_CODE")
?
msvc doesn't expect a space after "/D" IIRC.
https://msdn.microsoft.com/en-us/library/aa235412(v=vs.60).aspx
Upvotes: -1
Reputation: 157
To enable you can use -DUSE_OLD_CODE:BOOL=ON and To disable USE_OLD_CODE use -DUSE_OLD_CODE:BOOL=OFF
Upvotes: 0