Skip to content

Commit

Permalink
add config template
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp committed Aug 13, 2021
1 parent e50ce8d commit 327d4a4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 56 deletions.
53 changes: 14 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,15 @@ set(UNITS_NAMESPACE
CACHE STRING "Top-level namespace name. Default is `units`."
)

option(UNITS_INSTALL "Enable installation of the units library" ON)
mark_as_advanced(UNITS_INSTALL)

cmake_dependent_option(
UNITS_WITH_CMAKE_PACKAGE
UNITS_INSTALL
"Generate and install cmake package files"
ON
"CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;UNITS_INSTALL;NOT UNITS_BINARY_ONLY_INSTALL"
"CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;NOT UNITS_BINARY_ONLY_INSTALL"
OFF
)

mark_as_advanced(UNITS_WITH_CMAKE_PACKAGE)
mark_as_advanced(UNITS_INSTALL)

cmake_dependent_option(
UNITS_BUILD_FUZZ_TARGETS "Build the targets for a fuzzing system" OFF
Expand All @@ -113,12 +110,9 @@ set(UNITS_CLANG_TIDY_OPTIONS
mark_as_advanced(UNITS_CLANG_TIDY_OPTIONS)
mark_as_advanced(UNITS_CLANG_TIDY)

# Install instructions for this target
if(UNITS_WITH_CMAKE_PACKAGE)
set(UNITS_LIBRARY_EXPORT_COMMAND EXPORT unitsConfig)
else(UNITS_WITH_CMAKE_PACKAGE)
set(UNITS_LIBRARY_EXPORT_COMMAND)
endif(UNITS_WITH_CMAKE_PACKAGE)

set(UNITS_LIBRARY_EXPORT_COMMAND EXPORT unitsTargets)
mark_as_advanced(UNITS_LIBRARY_EXPORT_COMMAND)

option(UNITS_HEADER_ONLY "Expose the units library as header-only" OFF)

Expand Down Expand Up @@ -193,32 +187,13 @@ if(UNITS_INSTALL)
if(UNITS_BUILD_STATIC_LIBRARY)
install(TARGETS compile_flags_target ${UNITS_LIBRARY_EXPORT_COMMAND})
endif()
if(UNITS_WITH_CMAKE_PACKAGE AND NOT UNITS_BINARY_ONLY_INSTALL)
install(EXPORT unitsTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
export(EXPORT unitsTargets NAMESPACE units::)
if(NOT UNITS_BINARY_ONLY_INSTALL)
configure_file(config/unitsConfig.cmake.in
"${PROJECT_BINARY_DIR}/unitsConfig.cmake" @ONLY)

install(${UNITS_LIBRARY_EXPORT_COMMAND} DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units)
export(${UNITS_LIBRARY_EXPORT_COMMAND} NAMESPACE units::)
write_basic_package_version_file(${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake COMPATIBILITY AnyNewerVersion)
install(FILES ${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units)
install(FILES ${PROJECT_BINARY_DIR}/unitsConfigVersion.cmake ${PROJECT_BINARY_DIR}/unitsConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/units)
endif()
endif()



#if(HELICS_WITH_CMAKE_PACKAGE)

# set(HELICS_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
# CACHE STRING "install path for HELICSConfig.cmake"
# )
# mark_as_advanced(HELICS_CMAKECONFIG_INSTALL_DIR)

# Export targets for importing build tree with find_package
# export(EXPORT helics-targets NAMESPACE HELICS::
# FILE ${PROJECT_BINARY_DIR}/helics-targets.cmake
# )

# install(
# EXPORT helics-targets
# NAMESPACE HELICS::
# DESTINATION ${HELICS_CMAKECONFIG_INSTALL_DIR}
# COMPONENT libs
# )
# endif()
endif()
4 changes: 2 additions & 2 deletions config/unitConfig.cmake.in → config/unitsConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ endif()

# These are IMPORTED targets created by FooBarTargets.cmake
set(UNITS_LIBRARIES units::units)
set(UNITS_WEBSERVER units::webserver)
set(UNITS_CONVERT units::convert
set(UNITS_WEBSERVER units::units_webserver)
set(UNITS_CONVERT units::units_convert)
16 changes: 8 additions & 8 deletions converter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ cmake_dependent_option(
)

if(UNITS_BUILD_CONVERTER_APP)
add_executable(unit_convert converter.cpp)
target_link_libraries(unit_convert PUBLIC units::units compile_flags_target)
target_include_directories(unit_convert PRIVATE ${PROJECT_SOURCE_DIR}/ThirdParty)
add_executable(units_convert converter.cpp)
target_link_libraries(units_convert PUBLIC units::units compile_flags_target)
target_include_directories(units_convert PRIVATE ${PROJECT_SOURCE_DIR}/ThirdParty)
target_compile_definitions(
unit_convert PUBLIC UNITS_VERSION_STRING="${UNITS_VERSION}"
units_convert PUBLIC UNITS_VERSION_STRING="${UNITS_VERSION}"
)
if(CMAKE_CXX_STANDARD GREATER 16)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION
VERSION_EQUAL 8
)
target_link_libraries(unit_convert PRIVATE -lstdc++fs)
target_link_libraries(unit_sconvert PRIVATE -lstdc++fs)
endif()
endif()

if (UNITS_INSTALL)
install(TARGETS unit_convert
EXPORT unitsTargets
install(TARGETS units_convert
${UNITS_LIBRARY_EXPORT_COMMAND}
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT units_convert)
endif()

add_executable(units::units_convert ALIAS units_convert)
endif()
12 changes: 6 additions & 6 deletions units/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ if(UNITS_BUILD_SHARED_LIBRARY OR BUILD_SHARED_LIBS)
elseif(UNITS_HEADER_ONLY)
add_library(header_only INTERFACE)
target_include_directories(
header_only INTERFACE $<BUILD_INTERFACE:${UNITS_SOURCE_DIR}>
header_only INTERFACE $<BUILD_INTERFACE:${units_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_definitions(header_only INTERFACE UNITS_HEADER_ONLY)
if(UNITS_INSTALL)
if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL)
install(TARGETS header_only ${UNITS_LIBRARY_EXPORT_COMMAND})
endif()
if(UNITS_NAMESPACE)
Expand All @@ -61,7 +61,7 @@ elseif(UNITS_HEADER_ONLY)
add_library(units::header_only ALIAS header_only)
elseif(UNITS_BUILD_OBJECT_LIBRARY)
add_library(units OBJECT ${units_source_files} ${units_header_files})
target_include_directories(units PRIVATE $<BUILD_INTERFACE:${UNITS_SOURCE_DIR}>)
target_include_directories(units PRIVATE $<BUILD_INTERFACE:${units_SOURCE_DIR}>)

if(UNITS_NAMESPACE)
target_compile_definitions(units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE})
Expand Down Expand Up @@ -93,11 +93,11 @@ else()
if(UNITS_BASE_TYPE)
target_compile_definitions(units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE})
endif()
if(UNITS_INSTALL)
if(UNITS_INSTALL AND NOT UNITS_BINARY_ONLY_INSTALL)
install(TARGETS units ${UNITS_LIBRARY_EXPORT_COMMAND}
DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION include/units
DESTINATION ${CMAKE_INSTALL_LIBDIR} # INCLUDES DESTINATION include/${PROJECT_NAME}
)
endif(UNITS_INSTALL)
endif()
if(CMAKE_BUILD_TYPE STREQUAL Coverage)
set_source_files_properties(foo.cpp PROPERTIES COMPILE_FLAGS -Wno-effc++)
endif()
Expand Down
2 changes: 1 addition & 1 deletion webserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if(CMAKE_VERSION VERSION_GREATER 3.12)

if (UNITS_INSTALL)
install(TARGETS units_webserver
EXPORT unitsTargets
${UNITS_LIBRARY_EXPORT_COMMAND}
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT units_webserver)
endif()
add_executable(units::units_webserver ALIAS units_webserver)
Expand Down

0 comments on commit 327d4a4

Please sign in to comment.