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).
This commit is contained in:
Peter Wu 2016-03-13 12:22:33 +01:00
parent bdb6581990
commit 7f8110601e
4 changed files with 12 additions and 17 deletions

View File

@ -1,11 +1,10 @@
if(ENABLE_EXAMPLES) if(ENABLE_EXAMPLES)
# XXX replace this by lists (WARNCFLAGS_list) file(GLOB c_sources *.c)
string(REPLACE " " ";" c_flags "${WARNCFLAGS}") set_source_files_properties(${c_sources} PROPERTIES
string(REPLACE " " ";" cxx_flags "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") COMPILE_FLAGS "${WARNCFLAGS}")
add_compile_options( file(GLOB cxx_sources *.cc)
"$<$<COMPILE_LANGUAGE:C>:${c_flags}>" set_source_files_properties(${cxx_sources} PROPERTIES
"$<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>" COMPILE_FLAGS "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}")
)
include_directories( include_directories(
${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}

View File

@ -26,7 +26,6 @@ set(NGHTTP2_SOURCES
# Public shared library # Public shared library
add_library(nghttp2 SHARED ${NGHTTP2_SOURCES}) add_library(nghttp2 SHARED ${NGHTTP2_SOURCES})
# Needed because the object files are linked into a shared library.
set_target_properties(nghttp2 PROPERTIES set_target_properties(nghttp2 PROPERTIES
COMPILE_FLAGS "${WARNCFLAGS}" COMPILE_FLAGS "${WARNCFLAGS}"
VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}

View File

@ -1,12 +1,11 @@
add_subdirectory(includes) add_subdirectory(includes)
# XXX replace this by lists (WARNCFLAGS_list) file(GLOB c_sources *.c)
string(REPLACE " " ";" c_flags "${WARNCFLAGS}") set_source_files_properties(${c_sources} PROPERTIES
string(REPLACE " " ";" cxx_flags "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}") COMPILE_FLAGS "${WARNCFLAGS}")
add_compile_options( file(GLOB cxx_sources *.cc)
"$<$<COMPILE_LANGUAGE:C>:${c_flags}>" set_source_files_properties(${cxx_sources} PROPERTIES
"$<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>" COMPILE_FLAGS "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}")
)
include_directories( include_directories(
"${CMAKE_SOURCE_DIR}/lib/includes" "${CMAKE_SOURCE_DIR}/lib/includes"
@ -246,7 +245,6 @@ if(ENABLE_ASIO_LIB)
${OPENSSL_LIBRARIES} ${OPENSSL_LIBRARIES}
${Boost_LIBRARIES} ${Boost_LIBRARIES}
) )
# XXX use add_compile_options with a list instead of COMPILE_FLAGS
set_target_properties(nghttp2_asio PROPERTIES set_target_properties(nghttp2_asio PROPERTIES
VERSION 1.0.0 SOVERSION 1) VERSION 1.0.0 SOVERSION 1)

View File

@ -1,6 +1,5 @@
# XXX testdata/: EXTRA_DIST = cacert.pem index.html privkey.pem # XXX testdata/: EXTRA_DIST = cacert.pem index.html privkey.pem
if(HAVE_CUNIT) if(HAVE_CUNIT)
# XXX replace this by lists (WARNCFLAGS_list)
string(REPLACE " " ";" c_flags "${WARNCFLAGS}") string(REPLACE " " ";" c_flags "${WARNCFLAGS}")
add_compile_options(${c_flags}) add_compile_options(${c_flags})