Skip to content

Commit 5cf95f6

Browse files
authored
Merge pull request #123 from cschreib/cmake
Revert change in CMake target name for the header-only build
2 parents 4d7abc8 + c3dd9d4 commit 5cf95f6

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

CMakeLists.txt

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,24 @@ endfunction()
131131

132132
if (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)
149148
else()
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)
175173
endif()
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

185187
include(CMakePackageConfigHelpers)
186188
configure_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)
237242
endif()

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ include(FetchContent)
125125
126126
FetchContent_Declare(snitch
127127
GIT_REPOSITORY https://github.com/cschreib/snitch.git
128-
GIT_TAG v1.0.0) # update version number as needed
128+
GIT_TAG v1.2.0) # update version number as needed
129129
FetchContent_MakeAvailable(snitch)
130130
131131
set(YOUR_TEST_FILES
@@ -150,15 +150,15 @@ set(SNITCH_HEADER_ONLY 1)
150150
151151
FetchContent_Declare(snitch
152152
GIT_REPOSITORY https://github.com/cschreib/snitch.git
153-
GIT_TAG v1.0.0) # update version number as needed
153+
GIT_TAG v1.2.0) # update version number as needed
154154
FetchContent_MakeAvailable(snitch)
155155
156156
set(YOUR_TEST_FILES
157157
# add your test files here...
158158
)
159159
160160
add_executable(my_tests ${YOUR_TEST_FILES})
161-
target_link_libraries(my_tests PRIVATE snitch::snitch)
161+
target_link_libraries(my_tests PRIVATE snitch::snitch-header-only)
162162
```
163163

164164
One (and only one!) of your test files needs to include _snitch_ as:

cmake/snitch-config.cmake.in

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
@PACKAGE_INIT@
22

3-
include("${CMAKE_CURRENT_LIST_DIR}/snitch-targets.cmake")
3+
file(GLOB CONFIG_FILES "${CMAKE_CURRENT_LIST_DIR}/snitch*-targets.cmake")
4+
foreach(f ${CONFIG_FILES})
5+
include(${f})
46

5-
if (NOT TARGET snitch::snitch)
6-
add_library(snitch::snitch ALIAS snitch)
7-
endif ()
7+
string(REGEX MATCH "${CMAKE_CURRENT_LIST_DIR}/(snitch.*)-targets.cmake" match ${f})
8+
set(target ${CMAKE_MATCH_1})
9+
10+
if (NOT TARGET snitch::${target})
11+
add_library(snitch::${target} ALIAS ${target})
12+
endif()
13+
endforeach()

0 commit comments

Comments
 (0)