I would like to change the compile settings in a "subproject" in Cmake instantiated with ExternalProject_Add
(ExternalProject — CMake Documentation). How could I do that?
As an example: in pico-sdk, I usually have include(pico_sdk_import.cmake)
in my own project CMakeLists.txt, which eventually loads the file FindPioasm.cmake, which has this:
set(PioasmBuild_TARGET PioasmBuild)
set(Pioasm_TARGET Pioasm)
if (NOT TARGET ${PioasmBuild_TARGET})
pico_message_debug("PIOASM will need to be built")
# message("Adding external project ${PioasmBuild_Target} in ${CMAKE_CURRENT_LIST_DIR}}")
ExternalProject_Add(${PioasmBuild_TARGET}
PREFIX pioasm SOURCE_DIR ${PIOASM_SOURCE_DIR}
BINARY_DIR ${PIOASM_BINARY_DIR}
BUILD_ALWAYS 1 # force dependency checking
INSTALL_COMMAND ""
CMAKE_CACHE_ARGS "-DPIOASM_EXTRA_SOURCE_FILES:STRING=${PIOASM_EXTRA_SOURCE_FILES}"
)
endif()
When I eventually run make VERBOSE=1 PioasmBuild
, I eventually get the compile command line:
...
[ 10%] Building CXX object CMakeFiles/pioasm.dir/main.cpp.obj
/path/to/g++.exe @CMakeFiles/pioasm.dir/includes_CXX.rsp -std=gnu++11 -o CMakeFiles/pioasm.dir/main.cpp.obj -c /path/to/pico-sdk/tools/pioasm/main.cpp
...
So, I would like to add options to this compiler command line, like -Wall
or -DDEFINE
, per source file - or if that is not possible, for all compiler invocations for files in the external project...
For the "normal"/actual CMake project, so far I have used set_source_files_properties(/path/to/file.cpp PROPERTIES COMPILE_FLAGS "-DDEFINE")
with great success; however, probably because it is an external project, set_source_files_properties(${PICO_SDK_PATH}/tools/pioasm/main.cpp PROPERTIES COMPILE_FLAGS "-DDEFINE")
does not seem to make any difference at all.
So, how can I change the compile options/settings/properties in CMake for files defined in a CMake ExternalProject? And would I do those changes before or after the include(pico_sdk_import.cmake)
line (which ultimately "includes" the external project) in my project's CMakeLists.txt file?