From c8ee66361b607cc92df9f4d131cf2f826546dcfa Mon Sep 17 00:00:00 2001 From: Willy Scheibel Date: Tue, 9 May 2017 14:24:08 +0200 Subject: [PATCH] Fix cmake initialization regarding policy configuration --- CMakeLists.txt | 23 +++++++++++++++-------- cmake/Custom.cmake | 13 ------------- cmake/GenerateTemplateExportHeader.cmake | 12 ++++++++++++ 3 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 cmake/GenerateTemplateExportHeader.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 368c810..f2d0df8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,20 @@ # CMake version cmake_minimum_required(VERSION 3.0 FATAL_ERROR) -# Include cmake modules +# +# Configure CMake environment +# + +# Register general cmake commands +include(cmake/Custom.cmake) +# Set policies +set_policy(CMP0028 NEW) # ENABLE CMP0028: Double colon in target name means ALIAS or IMPORTED target. +set_policy(CMP0054 NEW) # ENABLE CMP0054: Only interpret if() arguments as variables or keywords when unquoted. +set_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default. +set_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types. + +# Include cmake modules list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(GenerateExportHeader) @@ -19,15 +31,10 @@ if (${CMAKE_VERSION} VERSION_GREATER "3.2") include(WriteCompilerDetectionHeader OPTIONAL RESULT_VARIABLE WriterCompilerDetectionHeaderFound) endif() +# Include custom cmake modules include(cmake/GetGitRevisionDescription.cmake) -include(cmake/Custom.cmake) include(cmake/HealthCheck.cmake) - -# Set policies -set_policy(CMP0028 NEW) # ENABLE CMP0028: Double colon in target name means ALIAS or IMPORTED target. -set_policy(CMP0054 NEW) # ENABLE CMP0054: Only interpret if() arguments as variables or keywords when unquoted. -set_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default. -set_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types. +include(cmake/GenerateTemplateExportHeader.cmake) # diff --git a/cmake/Custom.cmake b/cmake/Custom.cmake index 4e44820..e0e690f 100644 --- a/cmake/Custom.cmake +++ b/cmake/Custom.cmake @@ -44,16 +44,3 @@ function(list_extract OUTPUT REGEX) set(${OUTPUT} ${${OUTPUT}} PARENT_SCOPE) endfunction(list_extract) - - -# Creates an export header similar to generate_export_header, but for templates. -# The main difference is that for MSVC, templates must not get exported. -# When the file ${export_file} is included in source code, the macro ${target_id}_TEMPLATE_API -# may get used to define public visibility for templates on GCC and Clang platforms. -function(generate_template_export_header target target_id export_file) - if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") - configure_file(${PROJECT_SOURCE_DIR}/source/codegeneration/template_msvc_api.h.in ${CMAKE_CURRENT_BINARY_DIR}/${export_file}) - else() - configure_file(${PROJECT_SOURCE_DIR}/source/codegeneration/template_api.h.in ${CMAKE_CURRENT_BINARY_DIR}/${export_file}) - endif() -endfunction() diff --git a/cmake/GenerateTemplateExportHeader.cmake b/cmake/GenerateTemplateExportHeader.cmake new file mode 100644 index 0000000..7f8ea88 --- /dev/null +++ b/cmake/GenerateTemplateExportHeader.cmake @@ -0,0 +1,12 @@ + +# Creates an export header similar to generate_export_header, but for templates. +# The main difference is that for MSVC, templates must not get exported. +# When the file ${export_file} is included in source code, the macro ${target_id}_TEMPLATE_API +# may get used to define public visibility for templates on GCC and Clang platforms. +function(generate_template_export_header target target_id export_file) + if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") + configure_file(${PROJECT_SOURCE_DIR}/source/codegeneration/template_msvc_api.h.in ${CMAKE_CURRENT_BINARY_DIR}/${export_file}) + else() + configure_file(${PROJECT_SOURCE_DIR}/source/codegeneration/template_api.h.in ${CMAKE_CURRENT_BINARY_DIR}/${export_file}) + endif() +endfunction()