@@ -131,23 +131,24 @@ endfunction()
131131
132132if (NOT SNITCH_HEADER_ONLY)
133133 # Build as a standard library (static or dynamic) with header.
134- add_library (snitch ${SNITCH_INCLUDES} ${SNITCH_SOURCES} )
135- add_library (snitch::snitch ALIAS snitch)
136- set_target_properties (snitch PROPERTIES EXPORT_NAME snitch::snitch)
134+ set (SNITCH_TARGET_NAME snitch)
137135
138- target_compile_features (snitch PUBLIC cxx_std_20)
139- target_include_directories (snitch PUBLIC
136+ add_library (${SNITCH_TARGET_NAME} ${SNITCH_INCLUDES} ${SNITCH_SOURCES} )
137+ target_compile_features (${SNITCH_TARGET_NAME} PUBLIC cxx_std_20)
138+ target_include_directories (${SNITCH_TARGET_NAME} PUBLIC
140139 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include >
141140 $<BUILD_INTERFACE:${PROJECT_BINARY_DIR} >
142141 $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX} /include >)
143142
144- configure_snitch_exports(snitch )
143+ configure_snitch_exports(${SNITCH_TARGET_NAME} )
145144
146145 install (
147146 FILES ${SNITCH_INCLUDES}
148147 DESTINATION ${CMAKE_INSTALL_PREFIX} /include /snitch)
149148else ()
150149 # Build as a header-only library.
150+ set (SNITCH_TARGET_NAME snitch-header-only)
151+
151152 find_package (Python3)
152153
153154 add_custom_command (
@@ -160,12 +161,9 @@ else()
160161 ${SNITCH_SOURCES_INDIVIDUAL}
161162 ${PROJECT_SOURCE_DIR} /make_snitch_all.py)
162163
163- add_library (snitch INTERFACE ${PROJECT_BINARY_DIR} /snitch/snitch_all.hpp)
164- add_library (snitch::snitch ALIAS snitch)
165- set_target_properties (snitch PROPERTIES EXPORT_NAME snitch::snitch)
166-
167- target_compile_features (snitch INTERFACE cxx_std_20)
168- target_include_directories (snitch INTERFACE
164+ add_library (${SNITCH_TARGET_NAME} INTERFACE ${PROJECT_BINARY_DIR} /snitch/snitch_all.hpp)
165+ target_compile_features (${SNITCH_TARGET_NAME} INTERFACE cxx_std_20)
166+ target_include_directories (${SNITCH_TARGET_NAME} INTERFACE
169167 $<BUILD_INTERFACE:${PROJECT_BINARY_DIR} >
170168 $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX} /include >)
171169
@@ -174,13 +172,17 @@ else()
174172 DESTINATION ${CMAKE_INSTALL_PREFIX} /include /snitch)
175173endif ()
176174
175+ # Common properties
176+ add_library (snitch::${SNITCH_TARGET_NAME} ALIAS ${SNITCH_TARGET_NAME} )
177+ set_target_properties (${SNITCH_TARGET_NAME} PROPERTIES EXPORT_NAME snitch::${SNITCH_TARGET_NAME} )
178+
177179# Setup CMake config file
178- install (TARGETS snitch EXPORT snitch -targets)
180+ install (TARGETS ${SNITCH_TARGET_NAME} EXPORT ${SNITCH_TARGET_NAME} -targets)
179181
180- install (EXPORT snitch -targets
182+ install (EXPORT ${SNITCH_TARGET_NAME} -targets
181183 DESTINATION ${CMAKE_INSTALL_PREFIX} /lib/cmake/snitch COMPONENT Development)
182184
183- export (EXPORT snitch -targets)
185+ export (EXPORT ${SNITCH_TARGET_NAME} -targets)
184186
185187include (CMakePackageConfigHelpers)
186188configure_package_config_file(
@@ -212,7 +214,6 @@ if (SNITCH_DO_TEST)
212214
213215 if (NOT SNITCH_HEADER_ONLY)
214216 add_library (snitch-testlib ${SNITCH_INCLUDES} ${SNITCH_SOURCES} )
215- add_dependencies (snitch-testlib snitch)
216217
217218 target_compile_features (snitch-testlib PUBLIC cxx_std_20)
218219 target_include_directories (snitch-testlib PUBLIC
@@ -224,7 +225,6 @@ if (SNITCH_DO_TEST)
224225 configure_snitch_for_tests(snitch-testlib PUBLIC )
225226 else ()
226227 add_library (snitch-testlib INTERFACE ${PROJECT_BINARY_DIR} /snitch/snitch_all.hpp)
227- add_dependencies (snitch-testlib snitch)
228228
229229 target_compile_features (snitch-testlib INTERFACE cxx_std_20)
230230 target_include_directories (snitch-testlib INTERFACE ${PROJECT_BINARY_DIR} )
@@ -233,5 +233,10 @@ if (SNITCH_DO_TEST)
233233 target_compile_definitions (snitch-testlib INTERFACE SNITCH_TEST_HEADER_ONLY)
234234 endif ()
235235
236+ # This dependency is not strictly needed, but it makes developing easier:
237+ # if the "real" library fails to build, we won't try to compile the version
238+ # used in the tests.
239+ add_dependencies (snitch-testlib ${SNITCH_TARGET_NAME} )
240+
236241 add_subdirectory (tests)
237242endif ()
0 commit comments