Skip to content

Commit 57a0319

Browse files
committed
fixup! [FIX] Improve build system when compiling with colpack
1 parent da0a5b7 commit 57a0319

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

CMakeLists.txt

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -173,34 +173,42 @@ endif()
173173
set(ADOLC_BITWORD_BITS 32)
174174
target_compile_definitions(adolc PUBLIC
175175
ADOLC_BITWORD_BITS=${ADOLC_BITWORD_BITS})
176-
if (ENABLE_SPARSE)
177-
if (WIN32)
178-
message(FATAL_ERROR "Sparse drivers require OpenMP, which is not supported on Windows/MSVC. ")
179-
endif()
180-
181-
find_package(ColPack)
182-
if (ColPack_FOUND)
183-
message(STATUS "Using system-installed ColPack at ${ColPack_DIR}")
184176

185-
# Prefer shared if it exists (usually the case)
186-
if (TARGET ColPack_static)
187-
target_link_libraries(adolc PRIVATE ColPack_static)
188-
else()
189-
message(FATAL_ERROR "ColPack was found but provides no usable CMake targets")
190-
endif()
177+
if (ENABLE_SPARSE)
178+
if (WIN32)
179+
message(FATAL_ERROR "Sparse drivers require OpenMP, which is not supported on Windows/MSVC. ")
191180
endif()
192181

193-
if (NOT ColPack_FOUND)
194-
message(STATUS "System ColPack not found! Pulling from https://github.com/TimSiebert1/ColPack")
182+
# System ColPack branch
183+
if (ColPack_DIR)
184+
find_package(ColPack CONFIG REQUIRED "${ColPack_DIR}")
185+
message(STATUS "Using system-installed ColPack at ${ColPack_DIR}")
186+
target_link_libraries(adolc PRIVATE ColPack::ColPack_shared)
187+
188+
else ()
189+
message(STATUS "System ColPack_DIR not provided! Pulling from https://github.com/TimSiebert1/ColPack")
195190
include(FetchContent)
196191
FetchContent_declare(
197192
ColPack
198193
GIT_REPOSITORY https://github.com/TimSiebert1/ColPack
199-
GIT_TAG 96eca73724eb517cfb2cc66d8be448e91a30483f # latest commit
194+
GIT_TAG 6ca3669b1b37f1d575cc0934628d09ee5cd8cb12 # latest commit
200195
CMAKE_ARGS -DENABLE_OPENMP=ON # colpack needs openmp to build
201196
)
202197
FetchContent_MakeAvailable(ColPack)
203-
target_link_libraries(adolc PRIVATE ColPack::ColPack_static)
198+
target_link_libraries(adolc PRIVATE ColPack::ColPack_shared)
199+
200+
# Ensure feature_summary lists it
201+
set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND ColPack)
202+
set_property(GLOBAL APPEND PROPERTY _CMAKE_ColPack_TYPE REQUIRED)
203+
204+
# Install ColPack if ADOL-C is installed
205+
if (TARGET ColPack_shared)
206+
install(TARGETS ColPack_shared
207+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
208+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
209+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
210+
)
211+
endif()
204212
endif()
205213
set(ADOLC_SPARSE "#define ADOLC_SPARSE 1")
206214
endif()
@@ -276,8 +284,11 @@ include(CMakePackageConfigHelpers)
276284
include(GNUInstallDirs)
277285

278286
install(TARGETS adolc
279-
EXPORT adolcTargets
280-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/adolc)
287+
EXPORT adolcTargets
288+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
289+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
290+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
291+
)
281292

282293
install(EXPORT adolcTargets
283294
FILE adolc-targets.cmake

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Customize the build with the following options
4545

4646
`-DENABLE_BOOST_POOL=1` Enable the use of boost pool (default=False)
4747

48-
`-DENABLE_SPARSE=1` Build with Colpack to enable sparse AD (default=False)
48+
`-DENABLE_SPARSE=1` Build with Colpack to enable sparse AD (default=False, ColPack is either downloaded via FetchContent or if `ColPack_DIR` provides a path to ColPack's `ColPackConfig.cmake` this is used instead)
4949

5050
`-DBUILD_INTERFACE=1` Build the c interface (default=False)
5151

0 commit comments

Comments
 (0)