logo
down
shadow

Wrap cache variables of a library when configuring my code in CMake


Wrap cache variables of a library when configuring my code in CMake

By : Danny Dulberg
Date : November 17 2020, 01:00 AM
I hope this helps . The key word is INTERNAL property of the variable. Take a look at this example:
Test/CMakeLists.txt:
code :
cmake_minimum_required(VERSION 2.8)

Project(Test)

add_subdirectory(Component1)
add_subdirectory(Component2)
cmake_minimum_required(VERSION 2.8.11)

project(Component1)

set(SOURCES test1.c)

set(Component1_CONF "SomeValue" CACHE STRING "Component1_CONF description")
message(STATUS "Component1_CONF=${Component1_CONF}")

add_library(Component1 ${SOURCES})
target_include_directories(
  Component1 INTERFACE
  "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
  "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
)
project(Component2)

set(SOURCES test1.c)

set(Component2_CONF "/etc/passwd" CACHE FILEPATH "Component2_CONF description")

add_executable(Component2 ${SOURCES})
target_link_libraries(Component2 Component1)
cmake_minimum_required(VERSION 2.8)

Project(Test)

set(Component1_CONF "Other value" CACHE INTERNAL "Component1_CONF forced value" FORCE)
add_subdirectory(Component1)
add_subdirectory(Component2)


Share : facebook icon twitter icon
When should I wrap variables with ${...} in CMake?

When should I wrap variables with ${...} in CMake?


By : user2411857
Date : March 29 2020, 07:55 AM
I hope this helps you . Quoting the CMake documentation:
code :
set(FOO "Hello there!")
message(FOO)     # prints FOO
message(${FOO})  # prints Hello there!
set(FOO TRUE)
if(FOO)
    message("Foo was set!")
endif()
unset(BLA)
set(FOO "BLA")
if(FOO)
    message("if(<variable>): True")
else()
    message("if(<variable>): False")
endif()
if(${FOO})
    message("if(<constant>): True")
else()
    message("if(<constant>): False")
endif()
configuring code coverage with cmake

configuring code coverage with cmake


By : Imrul Ashraf
Date : March 29 2020, 07:55 AM
To fix this issue A mismatch in gcov and gcc version was making this happen. gcc symlink /usr/bin/gcc was set to newest gcc, same for g++ but gcov in $PATH was still pointing to older version of gcov.
How to tell CMake not to cache variables

How to tell CMake not to cache variables


By : karishma koshta
Date : March 29 2020, 07:55 AM
hope this fix your issue Just to close this question, I followed the Fraser's suggestion : rerun plain cmake to update the file list. Also, the variables were not in the cache.
Can I setup default CMake cache variables to apply for all projects?

Can I setup default CMake cache variables to apply for all projects?


By : Avinash Xavier
Date : March 29 2020, 07:55 AM
hop of those help? There are several settings I need to provide to CMake which are the same on every project. It gets annoying having to specify these on the command line every time I blow away my build area and start again. , You may create "initial-cache" script
~/default.cmake:
cmake cache variables deleted when some change

cmake cache variables deleted when some change


By : GEtta
Date : March 29 2020, 07:55 AM
like below fixes the issue The conventional way to avoid this error is to set the compiler via an environmental variable, i.e:
code :
$ CXX=clang++ cmake .. -DCMAKE_CXX_STANDARD=17
# ...
$ cat CMakeCache.txt | grep STANDARD
CMAKE_CXX_STANDARD:STRING=17
$ env CXX=g++ cmake .. -DCMAKE_CXX_STANDARD=17
# ...
$ cat CMakeCache.txt | grep STANDARD
CMAKE_CXX_STANDARD:STRING=17 
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org