CMake – Can not make decisions based on CMAKE_SYSTEM_NAME

currently I am working on a project using CMake. I want to do stuff based on the value of CMAKE_SYSTEM_NAME. It seems that the CMake if statement does not work as I expected. message(STATUS "CMAKE_SYSTEM_NAME = >${CMAKE_SYSTEM_NAME}<") if(${CMAKE_SYSTEM_NAME} EQUAL "Windows") message(STATUS "Why am I not called?") else() message(STATUS "I should not be here!\nCMAKE_SYSTEM_NAME = >${CMAKE_SYSTEM_NAME}<.")… Read More CMake – Can not make decisions based on CMAKE_SYSTEM_NAME

Including .hpp files in CMakeLists.txt for a Multi DIR Project?

Problem: I am struggling to link the header files in the project correctly using CMake lists. All the example online seem to be simpler and the projects use "Modern CMake" with relations which I’m also unfamiliar with. Error: warn XXXXX.hpp is not a directory fatal error #include XXXXX.hpp: No such file or directory Back Ground… Read More Including .hpp files in CMakeLists.txt for a Multi DIR Project?

CMake how to link subproject with external library

I have the following Structure of my Project: CMakeLists.txt cmake CMakeLists.txt src server CMakeLists.txt impl server.cpp CMakeLitst.txt main.cpp I am trying to include subproject src that’s depends in my case on PostgreSQL. Cmake is configuring fine, but building subproject with error: libpq-fe.h: No such file or directory. PostgreSQL is finding ok and linking without subproject… Read More CMake how to link subproject with external library

How properly use find_library?

I have this struct of files: And i am trying to create executable file, but i have problem in road to this, when i am creating makefile. I created libsort by cmake like this: cmake_minimum_required(VERSION 3.22) project(sort) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/deploy) set(SOURCE_FILES src/sort.cpp) set(HEADERS_FILES include/sort.h) add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${HEADERS_FILES}) target_include_directories(${PROJECT_NAME} PUBLIC include) And by this i created… Read More How properly use find_library?

CMake: Could not find Python3 (found version 3.9.6)

I am trying to configure CMake (v3.26.0) to find a local Anaconda installation of Python3 (on Ventura 13.3.1) I am using but I am running into an issue with CMake detecting Python. In my CMake configuration script, I have: find_package(Python3 COMPONENTS Interpreter REQUIRED Python3_ROOT "${CMAKE_CURRENT_LIST_DIR}/../conda/bin") This correctly points CMake to the location of the local… Read More CMake: Could not find Python3 (found version 3.9.6)

String Generator Expression gives unexpected result

I have the following CMake code: add_library(iflib INTERFACE) target_compile_definitions(iflib INTERFACE GEN_EXP=$<IF:$<STREQUAL:"test","test">,"EQUAL","DIFFERENT"> ) Which sets the GEN_EXP definition to "EQUAL", as expected. However, when I compare with a variable: add_library(iflib INTERFACE) set(TEST_VAR "test") target_compile_definitions(iflib INTERFACE GEN_EXP=$<IF:$<STREQUAL:${TEST_VAR},"test">,"EQUAL","DIFFERENT"> ) The GEN_EXP definition becomes "DIFFERENT". Is it not possible to do this kind of comparison in Generator Expressions? >Solution… Read More String Generator Expression gives unexpected result

CMake not finding header files

This is a very basic CMake question. I installed xlsxwriter library with brew install xlsxwriter, which adds the library to the system: /usr/local/lib/libxlsxwriter.dylib and the header (a symlink) to /usr/local/include/xlsxwriter.h. Then, I have the following minimal CMakeLists.txt: cmake_minimum_required(VERSION 3.20) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) project(main) add_executable(${PROJECT_NAME} "main.cpp") find_library(XLSXWRITER_LIB xlsxwriter) message(${XLSXWRITER_LIB}) target_link_libraries(${PROJECT_NAME} PUBLIC ${XLSXWRITER_LIB}) I can verify… Read More CMake not finding header files

CMake FindCURL finds curl but doesn't set CURL_LIBRARIES and CURL_INCLUDE_DIRS

I have build the libcurl from source with cmake and installed to /usr/local/ and I used find_package(CURL 7.88.1 EXACT REQUIRED) in my project’s main CMakeLists.txt. It find CURL with 7.88.1 version, however, when I want to print CURL_LIBRARIES and CURL_INCLUDE_DIRS in CMakeLists.txt prints nothing. Furthermore, I tried to link the libcurl with CURL::libcurl which is… Read More CMake FindCURL finds curl but doesn't set CURL_LIBRARIES and CURL_INCLUDE_DIRS

How can I copy a directory that have symlinks in it with CMake during build time when using file(GLOB_RECURSE)?

The most straight forward way to copy a directory in CMake during build time is: add_custom_target(my-copy-dir ALL COMMAND ${CMAKE_COMMAND} -E copy_directory ${INPUT_DIR} ${OUTPUT_DIR}) However, this approach is not desired because the copy will be executed every single time even when everything is up-to-date, which slow things down. Therefore, the below approach is better file( GLOB_RECURSE… Read More How can I copy a directory that have symlinks in it with CMake during build time when using file(GLOB_RECURSE)?

How can I get dependency tracking for a copy of a target file when target-based genex for add_custom_command's OUTPUT param is not supported?

This is a follow-up to In CMake how to get target file name during CMake configuration I want to achieve something similar to the below: add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/to_zip/$<TARGET_FILE_NAME:Foo> DEPENDS Foo COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:Foo> ${CMAKE_BINARY_DIR}/to_zip/$<TARGET_FILE_NAME:Foo>) list(APPEND ALL_FILES_IN_TO_ZIP ${CMAKE_BINARY_DIR}/to_zip/$<TARGET_FILE_NAME:Foo>) add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/myzip.zip DEPENDS ${ALL_FILES_IN_TO_ZIP} COMMAND <zip everything up in ${CMAKE_BINARY_DIR}/to_zip>) add_custom_target(create-zip DEPENDS ${CMAKE_BINARY_DIR}/to_zip/myzip.zip) Basically, when… Read More How can I get dependency tracking for a copy of a target file when target-based genex for add_custom_command's OUTPUT param is not supported?