Commit 17bb8471 authored by Martin Heistermann's avatar Martin Heistermann
Browse files

CMake improvements;

- always set project name
- be more careful setting include directories
- install targets and version file, export package
- CMakeConfig file: only include targets.cmake if target does not exist yet.
parent 2679675f
Pipeline #12051 passed with stages
in 13 minutes and 5 seconds
...@@ -3,10 +3,7 @@ if (WIN32) ...@@ -3,10 +3,7 @@ if (WIN32)
cmake_minimum_required (VERSION 3.13) cmake_minimum_required (VERSION 3.13)
endif() endif()
#Only set project name if CoMISo is built as stand-alone library project(CoMISo VERSION 1.1.0)
if("${PROJECT_NAME}" STREQUAL "")
project(CoMISo)
endif()
# add our macro directory to cmake search path # add our macro directory to cmake search path
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
...@@ -409,19 +406,22 @@ link_directories(${COMISO_LINK_DIRECTORIES}) ...@@ -409,19 +406,22 @@ link_directories(${COMISO_LINK_DIRECTORIES})
acg_add_library (CoMISo SHARED ${ui} ${sources} ${headers} ) acg_add_library (CoMISo SHARED ${ui} ${sources} ${headers} )
add_library(CoMISo::CoMISo ALIAS CoMISo) add_library(CoMISo::CoMISo ALIAS CoMISo)
target_include_directories (CoMISo PUBLIC target_include_directories(CoMISo
$<BUILD_INTERFACE: PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>
${CMAKE_CURRENT_SOURCE_DIR}/../ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..> # TODO: this is dangerous!
${CMAKE_CURRENT_BINARY_DIR} $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/>
${CMAKE_CURRENT_BINARY_DIR}/../> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<INSTALL_INTERFACE:include>
${COMISO_INCLUDE_DIRECTORIES}
) )
get_target_property(INC_DIRS CoMISo INCLUDE_DIRECTORIES) foreach(_incdir ${COMISO_INCLUDE_DIRECTORIES})
target_include_directories(CoMISo PUBLIC "$<BUILD_INTERFACE:${_incdir}>")
endforeach()
#get_target_property(INC_DIRS CoMISo INCLUDE_DIRECTORIES)
#get_target_property(INT_INC_DIRS CoMISo INTERFACE_INCLUDE_DIRECTORIES)
#message("Target CoMISo include dirs: ${INC_DIRS}") #message("Target CoMISo include dirs: ${INC_DIRS}")
#message("Target CoMISo int include dirs: ${INT_INC_DIRS}")
#message("COMISO_INCLUDE_DIRECTORIES: ${COMISO_INCLUDE_DIRECTORIES}") #message("COMISO_INCLUDE_DIRECTORIES: ${COMISO_INCLUDE_DIRECTORIES}")
#message("COMISO_LINK_DIRECTORIES: ${COMISO_LINK_DIRECTORIES}") #message("COMISO_LINK_DIRECTORIES: ${COMISO_LINK_DIRECTORIES}")
...@@ -464,13 +464,13 @@ if ( QT5_FOUND ) ...@@ -464,13 +464,13 @@ if ( QT5_FOUND )
if ( NOT WIN32 ) if ( NOT WIN32 )
# Allow targets depending on ACG find the autogenerated header files # Allow targets depending on ACG find the autogenerated header files
target_include_directories( CoMISo PUBLIC #target_include_directories( CoMISo PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/CoMISo_autogen/include ) # ${CMAKE_CURRENT_BINARY_DIR}/CoMISo_autogen/include )
else() else()
# Allow targets depending on ACG find the autogenerated header files # Allow targets depending on ACG find the autogenerated header files
target_include_directories( CoMISo PUBLIC #target_include_directories( CoMISo PUBLIC
$<$<CONFIG:Debug>:${CMAKE_CURRENT_BINARY_DIR}/CoMISo_autogen/include_Debug/> # $<$<CONFIG:Debug>:${CMAKE_CURRENT_BINARY_DIR}/CoMISo_autogen/include_Debug/>
$<$<CONFIG:Release>:${CMAKE_CURRENT_BINARY_DIR}/CoMISo_autogen/include_Release/> ) # $<$<CONFIG:Release>:${CMAKE_CURRENT_BINARY_DIR}/CoMISo_autogen/include_Release/> )
endif() endif()
endif() endif()
...@@ -576,7 +576,25 @@ if (COMISO_BUILD_EXAMPLES ) ...@@ -576,7 +576,25 @@ if (COMISO_BUILD_EXAMPLES )
endif (COMISO_BUILD_EXAMPLES ) endif (COMISO_BUILD_EXAMPLES )
# Only create install target, when we are building CoMISo standalone # Only create install target, when we are building CoMISo standalone
if(${PROJECT_NAME} MATCHES "CoMISo") if(NOT COMISO_NO_INSTALL)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/CoMISo)
write_basic_package_version_file(
CoMISoConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/CoMISoConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CoMISoConfig.cmake"
DESTINATION ${INSTALL_CONFIGDIR})
# Install library # Install library
install (TARGETS CoMISo EXPORT CoMISoTargets install (TARGETS CoMISo EXPORT CoMISoTargets
...@@ -613,6 +631,10 @@ if(${PROJECT_NAME} MATCHES "CoMISo") ...@@ -613,6 +631,10 @@ if(${PROJECT_NAME} MATCHES "CoMISo")
DESTINATION cmake DESTINATION cmake
) )
export(EXPORT CoMISoTargets
NAMESPACE CoMISo::)
export(PACKAGE CoMISo)
endif() endif()
list(REMOVE_AT CMAKE_MODULE_PATH -1) list(REMOVE_AT CMAKE_MODULE_PATH -1)
include(CMakeFindDependencyMacro) if(NOT TARGET CoMISo::CoMISo)
include("${CMAKE_CURENT_LIST_DIR}/CoMISoTargets.cmake")
endif()
# Add the targets file
include("${CMAKE_CURRENT_LIST_DIR}/CoMISoTargets.cmake")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment