0

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

5
  • Do you mean you're changing the FALSE part to true or the BOOL part to true? Commented Sep 21, 2017 at 15:19
  • 1
    Could be a duplicate of stackoverflow.com/a/10364240/1597714 Commented Sep 21, 2017 at 15:19
  • I am setting the FALSE part to TRUE. Edited above. Thank you. Commented Sep 21, 2017 at 15:25
  • Welcome to Stack Overflow. Please add the CMakeLists.txt code also that translates the CMake variable to something your compiler gets. Commented Sep 21, 2017 at 15:53
  • Added CMakeLists.txt. Commented Sep 21, 2017 at 16:13

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

Comments

-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.