From 7f8110601eef397533a272d0b0e9a2e5842431c6 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 13 Mar 2016 12:22:33 +0100 Subject: [PATCH] cmake: fix compatibility with cmake before 3.3 The COMPILE_LANGUAGE generator expression is only supported since CMake 3.3. Moreover, it does not work with all generators (works with Makefile and Ninja, but not with Visual Studio). target_compile_options would only work if a target does not mix C and C++ sources, since the flags are intended to be set for a specific language, use set_source_files_properties instead. This approach is also less repetitive. Drop the idea of using lists and COMPILE_OPTIONS, set_source_files_properties only understands COMPILE_FLAGS (a single string, not a list). --- examples/CMakeLists.txt | 13 ++++++------- lib/CMakeLists.txt | 1 - src/CMakeLists.txt | 14 ++++++-------- tests/CMakeLists.txt | 1 - 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d9054d11..96fae077 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,11 +1,10 @@ if(ENABLE_EXAMPLES) - # XXX replace this by lists (WARNCFLAGS_list) - string(REPLACE " " ";" c_flags "${WARNCFLAGS}") - string(REPLACE " " ";" cxx_flags "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") - add_compile_options( - "$<$:${c_flags}>" - "$<$:${cxx_flags}>" - ) + file(GLOB c_sources *.c) + set_source_files_properties(${c_sources} PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}") + file(GLOB cxx_sources *.cc) + set_source_files_properties(${cxx_sources} PROPERTIES + COMPILE_FLAGS "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") include_directories( ${CMAKE_SOURCE_DIR} diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index a6adc04d..ff512a45 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -26,7 +26,6 @@ set(NGHTTP2_SOURCES # Public shared library add_library(nghttp2 SHARED ${NGHTTP2_SOURCES}) -# Needed because the object files are linked into a shared library. set_target_properties(nghttp2 PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 83903dda..5bf8f972 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,11 @@ add_subdirectory(includes) -# XXX replace this by lists (WARNCFLAGS_list) -string(REPLACE " " ";" c_flags "${WARNCFLAGS}") -string(REPLACE " " ";" cxx_flags "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") -add_compile_options( - "$<$:${c_flags}>" - "$<$:${cxx_flags}>" -) +file(GLOB c_sources *.c) +set_source_files_properties(${c_sources} PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}") +file(GLOB cxx_sources *.cc) +set_source_files_properties(${cxx_sources} PROPERTIES + COMPILE_FLAGS "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") include_directories( "${CMAKE_SOURCE_DIR}/lib/includes" @@ -246,7 +245,6 @@ if(ENABLE_ASIO_LIB) ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ) - # XXX use add_compile_options with a list instead of COMPILE_FLAGS set_target_properties(nghttp2_asio PROPERTIES VERSION 1.0.0 SOVERSION 1) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8ce64154..4250ac3a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,5 @@ # XXX testdata/: EXTRA_DIST = cacert.pem index.html privkey.pem if(HAVE_CUNIT) - # XXX replace this by lists (WARNCFLAGS_list) string(REPLACE " " ";" c_flags "${WARNCFLAGS}") add_compile_options(${c_flags})