In my CMakeLists.txt
, global C and CXX flags are set using commands add_definitions()
and
add_compile_options.
Many attempts to retrieve the C/CXX flags:
${CMAKE_C_FLAGS}
and${CMAKE_CXX_FLAGS}
are empty${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}
is the original default CMake value
(e.g.-g
forCMAKE_C_FLAGS_DEBUG
)${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}
same as aboveget_cmake_property(def COMPILE_DEFINITIONS)
isNOTFOUND
get_cmake_property(opt COMPILE_OPTIONS)
is alsoNOTFOUND
I want to pass my custom C/CXX flags to an external project based on ./configure
:
ExternalProject_Add( my_external_lib
DEPENDS Threads::Threads
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}
BUILD_IN_SOURCE 1
UPDATE_COMMAND echo "Full clean" && make distclean
CONFIGURE_COMMAND ${CMAKE_CURRENT_LIST_DIR}/configure
--prefix=${CMAKE_BINARY_DIR}
--cc=${CMAKE_C_COMPILER}
--cxx=${CMAKE_CXX_COMPILER}
--CFLAGS=${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}
--CXXFLAGS=${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}
--LDFLAGS=${CMAKE_STATIC_LINKER_FLAGS_${CMAKE_BUILD_TYPE}}
--ARFLAGS=${CMAKE_STATIC_LINKER_FLAGS_${CMAKE_BUILD_TYPE}}
--enable-static
)
(1) How to get compilation flags set by add_definitions() and add_compile_options?
Note: I use CMake version 3.3.2
While writing the question, I realize I am wondering another question:
I use ccache
but the ./configure
script does not see my environment variables CC
and CXX
when I set them like that:
get_cmake_property(launcher RULE_LAUNCH_COMPILE)
set(ENV{CC} ${launcher} ${CMAKE_C_COMPILER})
set(ENV{CXX} ${launcher} ${CMAKE_CXX_COMPILER})
(2) Are these above CMake statements correct?
Oops I have again another question:
I retrieve the LDFLAGS
and ARFLAGS
from the same variable ${CMAKE_STATIC_LINKER_FLAGS}
.
(3) Is there another CMake variable to set ARFLAGS
?