11cmake_minimum_required (VERSION 3.18)
2+ project (devdat VERSION 1.0.0 LANGUAGES CXX)
23
3- # Project definition
4- project (devdat VERSION 0.0.1 LANGUAGES CXX CUDA)
4+ # Options
5+ option (BUILD_TESTING "Build tests" ON )
6+ option (DEVDAT_USE_SYSTEM_JSON "Use system-installed nlohmann_json" OFF )
57
68# Set C++ standard
79set (CMAKE_CXX_STANDARD 17)
810set (CMAKE_CXX_STANDARD_REQUIRED ON )
9- set (CMAKE_POSITION_INDEPENDENT_CODE ON )
11+ set (CMAKE_CXX_EXTENSIONS OFF )
1012
11- # Optionally set CUDA architectures (uncomment and set as needed)
12- # set(CMAKE_CUDA_ARCHITECTURES 60 70 75 80 86)
13+ # Check for CUDA and enable it (required for Thrust)
14+ include (CheckLanguage)
15+ check_language(CUDA)
16+ if (CMAKE_CUDA_COMPILER)
17+ enable_language (CUDA)
18+ set (CMAKE_CUDA_STANDARD 14)
19+ set (CMAKE_CUDA_STANDARD_REQUIRED ON )
20+ find_package (CUDAToolkit REQUIRED)
21+ else ()
22+ message (FATAL_ERROR "CUDA compiler not found! devdat requires CUDA for Thrust support." )
23+ endif ()
1324
14- # Install directories
15- include (GNUInstallDirs)
25+ # Handle nlohmann_json dependency
26+ if (DEVDAT_USE_SYSTEM_JSON)
27+ find_package (nlohmann_json REQUIRED)
28+ set (JSON_TARGET nlohmann_json::nlohmann_json)
29+ else ()
30+ # Download nlohmann_json at configure time
31+ include (FetchContent)
32+ FetchContent_Declare(
33+ nlohmann_json
34+ GIT_REPOSITORY https://github.com/nlohmann/json.git
35+ GIT_TAG v3.11.2
36+ )
37+ FetchContent_MakeAvailable(nlohmann_json)
38+
39+ # Create our own interface that doesn't need to be exported
40+ add_library (devdat_json_dep INTERFACE )
41+ target_include_directories (devdat_json_dep
42+ INTERFACE
43+ $<BUILD_INTERFACE:${nlohmann_json_SOURCE_DIR} /include >
44+ # Important: This is how consumers will find the headers
45+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
46+ )
47+
48+ # Install the nlohmann_json headers directly to include directory
49+ # This ensures they're found alongside our own headers
50+ install (
51+ DIRECTORY ${nlohmann_json_SOURCE_DIR} /include /
52+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
53+ )
54+
55+ set (JSON_TARGET devdat_json_dep)
56+ endif ()
57+
58+ # Create the library (header-only)
59+ add_library (devdat INTERFACE )
1660
17- # Fetch nlohmann_json (modern FetchContent usage )
18- include (FetchContent)
19- FetchContent_Declare(
20- json
21- GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
22- GIT_TAG v3.0.0
23- GIT_SHALLOW TRUE
61+ # Set target properties (note: header-only libraries use INTERFACE )
62+ target_include_directories (devdat
63+ INTERFACE
64+ $<BUILD_INTERFACE: ${CMAKE_CURRENT_SOURCE_DIR} / include >
65+ $<INSTALL_INTERFACE: ${CMAKE_INSTALL_INCLUDEDIR} >
66+ $<BUILD_INTERFACE: ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES} >
67+ $<INSTALL_INTERFACE: ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES} >
2468)
25- FetchContent_MakeAvailable(json)
2669
27- # Header-only library target
28- add_library (devdat INTERFACE )
29- target_include_directories (devdat INTERFACE
30- $<BUILD_INTERFACE: ${CMAKE_SOURCE_DIR} / include >
31- $<INSTALL_INTERFACE: ${CMAKE_INSTALL_INCLUDEDIR} >
70+ # Link dependencies (using our local target and CUDA)
71+ target_link_libraries (devdat
72+ INTERFACE
73+ ${JSON_TARGET}
74+ CUDA::toolkit
3275)
3376
34- # Alias for downstream usage
35- add_library (devdat ::devdat ALIAS devdat)
77+ # Add an alias target for use within the build tree
78+ add_library (${PROJECT_NAME} ::devdat ALIAS devdat)
3679
37- # Testing
38- include (CTest)
39- if (BUILD_TESTING)
40- add_subdirectory (tests)
41- endif ()
80+ # Installation
81+ include (GNUInstallDirs)
82+ set (INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME} )
4283
43- # === Installation ===
84+ # Install the headers
85+ install (
86+ DIRECTORY include /
87+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
88+ )
4489
90+ # Install the target (note: header-only libraries have special install syntax)
4591install (
46- TARGETS devdat
47- EXPORT devdat-config
48- INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
92+ TARGETS devdat
93+ EXPORT ${PROJECT_NAME} Targets
4994)
5095
96+ if (NOT DEVDAT_USE_SYSTEM_JSON)
97+ # Add our bundled dependency to the exported targets
98+ install (
99+ TARGETS devdat_json_dep
100+ EXPORT ${PROJECT_NAME} Targets
101+ )
102+ endif ()
103+
104+ # Export the targets
51105install (
52- EXPORT devdat-config
53- NAMESPACE devdat::
54- DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/devdat
106+ EXPORT ${PROJECT_NAME} Targets
107+ FILE ${PROJECT_NAME} Targets.cmake
108+ NAMESPACE ${PROJECT_NAME} ::
109+ DESTINATION ${INSTALL_CONFIGDIR}
55110)
56111
112+ # Create config files
113+ include (CMakePackageConfigHelpers)
114+
115+ # Create a config file that handles dependencies
116+ configure_file (
117+ ${CMAKE_CURRENT_SOURCE_DIR} /cmake/DevdatConfig.cmake.in
118+ ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} Config.cmake
119+ @ONLY
120+ )
121+
122+ write_basic_package_version_file(
123+ ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} ConfigVersion.cmake
124+ VERSION ${PROJECT_VERSION}
125+ COMPATIBILITY SameMajorVersion
126+ )
127+
128+ # Install the config files
57129install (
58- DIRECTORY ${CMAKE_CURRENT_LIST_DIR} /include /
59- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
130+ FILES
131+ ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} Config.cmake
132+ ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} ConfigVersion.cmake
133+ DESTINATION ${INSTALL_CONFIGDIR}
60134)
61135
62- # Feature summary
63- include (FeatureSummary)
64- feature_summary(WHAT ALL )
136+ # Add the tests if enabled
137+ if (BUILD_TESTING)
138+ enable_testing ()
139+ add_subdirectory (tests)
140+ endif ()
0 commit comments