0
votes

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

2
Do you mean you're changing the FALSE part to true or the BOOL part to true?Simple
Could be a duplicate of stackoverflow.com/a/10364240/1597714AMA
I am setting the FALSE part to TRUE. Edited above. Thank you.GUIDeveloper
Welcome to Stack Overflow. Please add the CMakeLists.txt code also that translates the CMake variable to something your compiler gets.Florian
Added CMakeLists.txt.GUIDeveloper

2 Answers

0
votes

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

0
votes

To enable you can use -DUSE_OLD_CODE:BOOL=ON and To disable USE_OLD_CODE use -DUSE_OLD_CODE:BOOL=OFF