Modularize compilation of main library
This commit is contained in:
@@ -18,10 +18,6 @@ if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
|
||||
endif (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
|
||||
message (STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
||||
|
||||
# all public header files are together with the source
|
||||
set (opm-core_INCLUDE_DIR "${PROJECT_SOURCE_DIR}")
|
||||
list (APPEND opm-core_INCLUDE_DIRS "${opm-core_INCLUDE_DIR}")
|
||||
|
||||
# additional search modules
|
||||
set (opm-core_MODULE_DIR "${PROJECT_SOURCE_DIR}/cmake/Modules")
|
||||
list (APPEND CMAKE_MODULE_PATH ${opm-core_MODULE_DIR})
|
||||
@@ -189,9 +185,6 @@ define_fc_func (
|
||||
APPEND "${PROJECT_BINARY_DIR}/config.h"
|
||||
)
|
||||
|
||||
# some CMake properties do not do list expansion
|
||||
string (REPLACE ";" " " opm-core_LINKER_FLAGS_STR "${opm-core_LINKER_FLAGS}")
|
||||
|
||||
# default to building a static library, but let user override
|
||||
if (DEFINED BUILD_SHARED_LIBS)
|
||||
set (_shared_def ${BUILD_SHARED_LIBS})
|
||||
@@ -205,47 +198,9 @@ else (BUILD_${opm-core_NAME}_SHARED)
|
||||
set (opm-core_LIBRARY_TYPE STATIC)
|
||||
endif (BUILD_${opm-core_NAME}_SHARED)
|
||||
|
||||
# name of the library should not contain dashes, as CMake will
|
||||
# define a symbol with that name, and those cannot contain dashes
|
||||
string (REPLACE "-" "" opm-core_TARGET "${opm-core_NAME}")
|
||||
|
||||
# create this library
|
||||
include_directories (${opm-core_INCLUDE_DIRS})
|
||||
link_directories (${opm-core_LIBRARY_DIRS})
|
||||
add_definitions (${opm-core_DEFINITIONS})
|
||||
add_library (${opm-core_TARGET} ${opm-core_LIBRARY_TYPE} ${opm-core_SOURCES})
|
||||
set (opm-core_VERSION "${opm-core_VERSION_MAJOR}.${opm-core_VERSION_MINOR}")
|
||||
set_target_properties (${opm-core_TARGET} PROPERTIES
|
||||
SOVERSION ${opm-core_VERSION_MAJOR}
|
||||
VERSION ${opm-core_VERSION}
|
||||
LINK_FLAGS "${opm-core_LINKER_FLAGS_STR}"
|
||||
)
|
||||
target_link_libraries (${opm-core_TARGET} ${opm-core_LIBRARIES})
|
||||
|
||||
# queue this executable to be stripped
|
||||
strip_debug_symbols (${opm-core_TARGET} opm-core_DEBUG)
|
||||
|
||||
# pre-compile common headers; this is setup *after* the library to pick
|
||||
# up extra options set there
|
||||
option (PRECOMPILE_HEADERS "Precompile common headers for speed." ON)
|
||||
mark_as_advanced (PRECOMPILE_HEADERS)
|
||||
if (PRECOMPILE_HEADERS)
|
||||
get_target_property (_type ${opm-core_TARGET} TYPE)
|
||||
precompile_header (CXX ${_type}
|
||||
HEADER "${opm-core_PRECOMP_CXX_HEADER}"
|
||||
TARGET opm-core_CXX_pch
|
||||
FLAGS opm-core_PRECOMP_CXX_FLAGS
|
||||
)
|
||||
# must set property on source files instead of entire target, because
|
||||
# it only applies to C++ modules (and cannot be used for C)
|
||||
set_source_files_properties (${opm-core_CXX_SOURCES} PROPERTIES
|
||||
OBJECT_DEPENDS "${opm-core_CXX_pch}"
|
||||
COMPILE_FLAGS "${opm-core_PRECOMP_CXX_FLAGS}"
|
||||
)
|
||||
message (STATUS "Precompiled headers: ${opm-core_CXX_pch}")
|
||||
else (PRECOMPILE_HEADERS)
|
||||
message (STATUS "Precompiled headers: disabled")
|
||||
endif (PRECOMPILE_HEADERS)
|
||||
# compile main library; pull in all required includes and libraries
|
||||
include (OpmCompile)
|
||||
opm_compile (opm-core)
|
||||
|
||||
# installation target: copy the library together with debug and
|
||||
# configuration files to system directories
|
||||
@@ -253,9 +208,6 @@ include (OpmInstall)
|
||||
opm_install (opm-core)
|
||||
message (STATUS "This build defaults to installing in ${CMAKE_INSTALL_PREFIX}")
|
||||
|
||||
# we need to know the name of the library which is generated
|
||||
get_target_property (opm-core_LIBRARY ${opm-core_TARGET} LOCATION)
|
||||
|
||||
# installation of CMake modules to help user programs locate the library
|
||||
include (OpmProject)
|
||||
opm_cmake_config (opm-core)
|
||||
|
||||
56
cmake/Modules/OpmCompile.cmake
Normal file
56
cmake/Modules/OpmCompile.cmake
Normal file
@@ -0,0 +1,56 @@
|
||||
# - Compile main library target
|
||||
|
||||
macro (opm_compile opm)
|
||||
# some CMake properties do not do list expansion
|
||||
string (REPLACE ";" " " ${opm}_LINKER_FLAGS_STR "${${opm}_LINKER_FLAGS}")
|
||||
|
||||
# name of the library should not contain dashes, as CMake will
|
||||
# define a symbol with that name, and those cannot contain dashes
|
||||
string (REPLACE "-" "" ${opm}_TARGET "${${opm}_NAME}")
|
||||
|
||||
# all public header files are together with the source
|
||||
set (${opm}_INCLUDE_DIR "${PROJECT_SOURCE_DIR}")
|
||||
list (APPEND ${opm}_INCLUDE_DIRS "${${opm}_INCLUDE_DIR}")
|
||||
|
||||
# create this library
|
||||
include_directories (${${opm}_INCLUDE_DIRS})
|
||||
link_directories (${${opm}_LIBRARY_DIRS})
|
||||
add_definitions (${${opm}_DEFINITIONS})
|
||||
add_library (${${opm}_TARGET} ${${opm}_LIBRARY_TYPE} ${${opm}_SOURCES})
|
||||
set (${opm}_VERSION "${${opm}_VERSION_MAJOR}.${${opm}_VERSION_MINOR}")
|
||||
set_target_properties (${${opm}_TARGET} PROPERTIES
|
||||
SOVERSION ${${opm}_VERSION_MAJOR}
|
||||
VERSION ${${opm}_VERSION}
|
||||
LINK_FLAGS "${${opm}_LINKER_FLAGS_STR}"
|
||||
)
|
||||
target_link_libraries (${${opm}_TARGET} ${${opm}_LIBRARIES})
|
||||
|
||||
# queue this executable to be stripped
|
||||
strip_debug_symbols (${${opm}_TARGET} ${opm}_DEBUG)
|
||||
|
||||
# pre-compile common headers; this is setup *after* the library to pick
|
||||
# up extra options set there
|
||||
option (PRECOMPILE_HEADERS "Precompile common headers for speed." ON)
|
||||
mark_as_advanced (PRECOMPILE_HEADERS)
|
||||
if (PRECOMPILE_HEADERS)
|
||||
get_target_property (_type ${${opm}_TARGET} TYPE)
|
||||
precompile_header (CXX ${_type}
|
||||
HEADER "${${opm}_PRECOMP_CXX_HEADER}"
|
||||
TARGET ${opm}_CXX_pch
|
||||
FLAGS ${opm}_PRECOMP_CXX_FLAGS
|
||||
)
|
||||
# must set property on source files instead of entire target, because
|
||||
# it only applies to C++ modules (and cannot be used for C)
|
||||
set_source_files_properties (${${opm}_CXX_SOURCES} PROPERTIES
|
||||
OBJECT_DEPENDS "${${opm}_CXX_pch}"
|
||||
COMPILE_FLAGS "${${opm}_PRECOMP_CXX_FLAGS}"
|
||||
)
|
||||
message (STATUS "Precompiled headers: ${${opm}_CXX_pch}")
|
||||
else (PRECOMPILE_HEADERS)
|
||||
message (STATUS "Precompiled headers: disabled")
|
||||
endif (PRECOMPILE_HEADERS)
|
||||
|
||||
# we need to know the name of the library which is generated
|
||||
get_target_property (${opm}_LIBRARY ${${opm}_TARGET} LOCATION)
|
||||
|
||||
endmacro (opm_compile opm)
|
||||
Reference in New Issue
Block a user