cmake - CMAKE_BUILD_TYPE not being used in CMakeLists.txt -


i'm having trouble setting default build configuration release, in cmakelists.txt file set cmake_build_type @ top of file with

#enable release always, configure vars set(cmake_build_type release) set(executable_name "particlesimulator") set(version_major 0) set(version_minor 2) 

but upon building project , opening solution, i'm presented debug mode, contrary specified in cmakelists file. doing wrong? i've looked @ of other question on there didn't see specific question.

a gist of cmakelists.txt

there 2 type of generators: single-configurations , multi-configurations.

single configurations

make-like generators: unix makefiles, nmake makefiles, mingw makefiles, ...

you set configuration type on generate step:

cmake -h. -b_builds/debug -dcmake_build_type=debug "-gunix makefiles" 

in case build step always debug:

> cmake --build _builds/debug     /usr/bin/c++ -g ... > cmake --build _builds/debug --config debug # `--config` ignored /usr/bin/c++ -g ... > cmake --build _builds/debug --config release # yep, ignored /usr/bin/c++ -g ... 

multi-configuration

ide generators: visual studio, xcode

cmake_build_type on generate step ignored, both:

> cmake -h. -b_builds -dcmake_build_type=debug "-gvisual studio 12 2013 win64" 

and

> cmake -h. -b_builds -dcmake_build_type=release "-gvisual studio 12 2013 win64" 

will have same effect:

enter image description here

this because configurations internal (i.e. _builds/msvc-opaque/release , _builds/msvc-opaque/debug or something, doesn't matter). can use --config options switch:

> cmake --build _builds --config release cl /o2 ... > cmake --build _builds --config debug cl /od ... 

control (?)

yes, can. define cmake_configuration_types:

# somewhere in cmakelists.txt message("generated config types: ${cmake_configuration_types}") 

default output:

-- detecting cxx compiler abi info - done generated config types: debug;release;minsizerel;relwithdebinfo -- configuring done 

rewrite it:

> cmake -h. -b_builds -dcmake_configuration_types="debug;release" "-gvisual studio 12 2013 win64" -- detecting cxx compiler abi info - done generated config types: debug;release -- configuring done 

enter image description here

you can define own config-type:

> cmake -h. -b_builds -dcmake_configuration_types="debug;myrelease" -dcmake_cxx_flags_myrelease="/my-rel-flag" -dcmake_exe_linker_flags_myrelease="/my-linker-flags" "-gvisual studio 12 2013 win64" 

enter image description here

and build:

cmake --build _builds --config myrelease

messy (?)

not @ if know trick :) how build/test config in script/ci server/documentation's build instruction etc:

> config=debug > cmake -h. -b_builds "-dcmake_build_type=${config}" # set debug makefile, ignored ide > cmake --build _builds --config "${config}" # build debug in ide, ignored makefile > (cd _builds && ctest -vv -c "${config}") # test debug in ide, ignored makefile 

bad pattern

if(cmake_build_type strequal debug) # burn fire!!! set(cmake_build_type mysuperrelease) # ready catch bug ide user... 

good one

set(cmake_cxx_flags_debug "${cmake_cxx_flags_debug} --my-debug-flags") 

works nice.

target_compile_definitions(mytarget public "$<$<config:debug>:mydebug_macro>") 

thank you! :) save day 1 programmer.

works me makefile, i'm happy ...

some quote nice book of nice guy know (emphasis mine):

why should bother? people program on variety of systems or use variety of compilers care lot because if don’t, forced waste time finding , fixing obscure bugs. people claim don’t care portability because use single system , feel can afford attitude ‘‘the language compiler implements.’’ narrow , shortsighted view. if program success, ported, have find , fix problems related implementation dependent features. in addition, programs need compiled other compilers same system, , future release of favorite compiler may things differently current one. far easier know , limit impact of implementation dependencies when program written try untangle mess afterwards.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -