Debian Codegraph @

CMakeLists.txt

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 cmake_minimum_required(VERSION 3.12)
2
3 include(cmake/ProjectVersion.cmake)
4
5 project(LibBGCode VERSION ${LibBGCode_VERSION})
6
7 # Set C++ standard
8 set(CMAKE_CXX_STANDARD 17)
9 set(CMAKE_CXX_STANDARD_REQUIRED ON)
10
11 set(_libname ${PROJECT_NAME})
12 string(TOLOWER ${_libname} _libname)
13 string(REPLACE "lib" "" _libname ${_libname})
14
15 option(${PROJECT_NAME}_BUILD_TESTS "Build unit tests" ON)
16 option(${PROJECT_NAME}_BUILD_COMPONENT_Binarize "Include Binarize component in the library" ON)
17 option(${PROJECT_NAME}_BUILD_SANITIZERS "Turn on sanitizers" OFF)
18
19 # Dependency build management
20 option(${PROJECT_NAME}_BUILD_DEPS "Build dependencies before the project" OFF)
21 option(${PROJECT_NAME}_DEPS_OUTPUT_QUIET "Don't print build output for dependencies" ON)
22 option(${PROJECT_NAME}_DEPS_SHARED "Build dependencies as shared libraries" OFF)
23 set(${PROJECT_NAME}_DEPS_PRESET "default" CACHE STRING "Preset of the dependencies when ${PROJECT_NAME}_BUILD_DEPS is ON")
24 set(${PROJECT_NAME}_DEPS_BUILD_DIR "" CACHE PATH "Binary dir of the dependencies build when ${PROJECT_NAME}_BUILD_DEPS is ON")
25
26 if (${PROJECT_NAME}_BUILD_DEPS)
27 include(deps/autobuild.cmake)
28 endif ()
29
30 if (NOT CMAKE_DEBUG_POSTFIX)
31 set(CMAKE_DEBUG_POSTFIX "d")
32 endif ()
33
34 include(CMakeDependentOption)
35 cmake_dependent_option(${PROJECT_NAME}_BUILD_COMPONENT_Convert "Include Convert component in the library" ON
36 "${PROJECT_NAME}_BUILD_COMPONENT_Binarize" OFF)
37 cmake_dependent_option(${PROJECT_NAME}_BUILD_CMD_TOOL "Include bgcode command line tool in the library" ON
38 "${PROJECT_NAME}_BUILD_COMPONENT_Convert" OFF)
39
40 if (EMSCRIPTEN)
41 cmake_dependent_option(${PROJECT_NAME}_BUILD_WASM "Include bgcode wasm module in the build" ON
42 "${PROJECT_NAME}_BUILD_COMPONENT_Convert" OFF)
43 endif ()
44
45 set(_selected_components "Core")
46 set(_selected_libs "${_libname}_core")
47 set(_highest_comp "Core")
48
49 # Set this if downstream would need to link additional boost
50 # components
51 set(Boost_DOWNSTREAM_COMPONENTS "")
52
53 set(namespace "${PROJECT_NAME}::")
54
55 # Create an export header
56 include(GenerateExportHeader)
57
58 set(_srcloc src/${PROJECT_NAME})
59
60 configure_file(
61 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in
62 ${PROJECT_BINARY_DIR}/version.rc
63 @ONLY)
64
65 if (CMAKE_COMPILER_IS_GNUCXX)
66 add_compile_options(-fvisibility=hidden)
67 endif ()
68
69 add_subdirectory(${_srcloc}/core)
70
71 if (${PROJECT_NAME}_BUILD_COMPONENT_Binarize)
72 add_subdirectory(${_srcloc}/binarize)
73
74 list(APPEND _selected_components Binarize)
75 list(APPEND _selected_libs ${_libname}_binarize)
76 set(_highest_comp "Binarize")
77 endif ()
78
79 if (${PROJECT_NAME}_BUILD_COMPONENT_Convert)
80 add_subdirectory(${_srcloc}/convert)
81
82 list(APPEND _selected_components Convert)
83 list(APPEND _selected_libs ${_libname}_convert)
84 set(_highest_comp "Convert")
85 endif ()
86
87 add_library(${_libname} INTERFACE)
88 target_link_libraries(${_libname} INTERFACE ${_selected_libs})
89
90 if (${PROJECT_NAME}_BUILD_CMD_TOOL)
91 add_subdirectory(${_srcloc}/cmd)
92 endif ()
93
94 if (${PROJECT_NAME}_BUILD_WASM)
95 add_subdirectory(${_srcloc}/wasm)
96 endif()
97
98 if (${PROJECT_NAME}_BUILD_PYTHON_BINDING)
99 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
100 endif ()
101
102 if(${PROJECT_NAME}_BUILD_TESTS)
103 enable_testing ()
104 add_subdirectory(tests)
105 endif()
106
107 # Create and install the CMake config script
108 include(CMakePackageConfigHelpers)
109 include(GNUInstallDirs)
110 set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
111
112 set(version_config "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
113 set(project_config "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
114
115 install(TARGETS ${_libname}
116 EXPORT ${PROJECT_NAME}{_highest_comp}Targets
117 INCLUDES DESTINATION include/${PROJECT_NAME}
118 )
119
120 foreach(_comp ${_selected_components})
121 # Install targets and headers
122 string(TOLOWER ${_comp} _comp_lower)
123 set(_export_targets ${_libname}_${_comp_lower})
124
125 set_target_properties(${_libname}_${_comp_lower}
126 PROPERTIES
127 VERSION ${PROJECT_VERSION}
128 SOVERSION ${PROJECT_VERSION})
129
130 install(TARGETS ${_export_targets}
131 EXPORT ${PROJECT_NAME}${_comp}Targets
132 INCLUDES DESTINATION include/${PROJECT_NAME}
133 )
134
135 install(FILES ${_srcloc}/${_comp_lower}/${_comp_lower}.hpp DESTINATION include/${PROJECT_NAME}/${_comp_lower})
136 install(FILES
137 ${PROJECT_BINARY_DIR}/${_comp_lower}/export.h DESTINATION include/${PROJECT_NAME}/${_comp_lower}/
138 )
139 install(
140 EXPORT "${PROJECT_NAME}${_comp}Targets"
141 NAMESPACE "${namespace}"
142 DESTINATION "${CONFIG_INSTALL_DIR}"
143 )
144 endforeach()
145
146 write_basic_package_version_file(
147 "${version_config}"
148 VERSION ${PROJECT_VERSION}
149 COMPATIBILITY SameMajorVersion
150 )
151
152 configure_package_config_file(
153 "cmake/Config.cmake.in"
154 "${project_config}"
155 INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}"
156 NO_CHECK_REQUIRED_COMPONENTS_MACRO
157 )
158
159 install(
160 FILES "${project_config}" "${version_config}"
161 DESTINATION "${CONFIG_INSTALL_DIR}"
162 )