Skip to content

Commit

Permalink
Update cmake files to address issue #12
Browse files Browse the repository at this point in the history
  * use GNUInstallDirs to enable fine-grained control of install dirs
  * set version property for clasp library
  * fix clasp header installation
  * add dependencies to cmake/clasp-config.cmake
  • Loading branch information
BenKaufmann committed Sep 3, 2017
1 parent fe3e176 commit f139715
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
24 changes: 20 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(GNUInstallDirs)

# Configuration options
option(CLASP_BUILD_APP "whether or not to build the clasp application" ON)
option(CLASP_BUILD_STATIC "whether or not to link statically (if supported)" OFF)
Expand Down Expand Up @@ -40,8 +42,15 @@ else()
string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
endif()
endif()
set(clasp_include_dest "include/clasp-${CLASP_VERSION}")
set(clasp_library_dest "lib/clasp-${CLASP_VERSION}")
set(clasp_include_dest "clasp-${CLASP_VERSION}")
set(clasp_library_dest "clasp-${CLASP_VERSION}")
set(cmake_dest "clasp-${CLASP_VERSION}/cmake")

if (CLASP_INSTALL_LIB AND NOT CMAKE_INSTALL_LIBDIR)
message(STATUS "LIBDIR no set - using lib")
set(CMAKE_INSTALL_LIBDIR lib)
endif()


# C++11 is required for building with threads
if (CLASP_BUILD_WITH_THREADS)
Expand Down Expand Up @@ -125,7 +134,14 @@ endif()
configure_file(cmake/clasp-config-version.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/clasp-config-version.cmake
@ONLY)

configure_file(cmake/clasp-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/clasp-config.cmake
@ONLY)

if (CLASP_INSTALL_LIB)
install(FILES cmake/clasp-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/clasp-config-version.cmake DESTINATION "${clasp_library_dest}")
install(EXPORT clasp DESTINATION "${clasp_library_dest}")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/clasp-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/clasp-config-version.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${cmake_dest}")
install(EXPORT clasp DESTINATION "${CMAKE_INSTALL_LIBDIR}/${cmake_dest}")
endif()

6 changes: 5 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ set(files
main.cpp)
add_executable(clasp ${files})
set_target_properties(clasp PROPERTIES FOLDER exe)
if (NOT CMAKE_INSTALL_BINDIR)
message(STATUS "BINDIR not set - using bin")
set(CMAKE_INSTALL_BINDIR "bin")
endif()
if (CLASP_BUILD_STATIC AND UNIX AND NOT APPLE)
if (CLASP_BUILD_WITH_THREADS)
string(CONCAT refs "-Wl,-u,pthread_cancel,-u,pthread_cond_broadcast,"
Expand All @@ -17,4 +21,4 @@ if (CLASP_BUILD_STATIC AND UNIX AND NOT APPLE)
endif()
target_link_libraries(clasp libclasp)

install(TARGETS clasp EXPORT clasp DESTINATION "bin")
install(TARGETS clasp EXPORT clasp DESTINATION ${CMAKE_INSTALL_BINDIR})
2 changes: 0 additions & 2 deletions cmake/clasp-config.cmake

This file was deleted.

8 changes: 8 additions & 0 deletions cmake/clasp-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include("${CMAKE_CURRENT_LIST_DIR}/clasp.cmake")

find_package(potassco 1.0 REQUIRED)

if(@CLASP_BUILD_WITH_THREADS@)
find_package(Threads REQUIRED)
endif()

35 changes: 19 additions & 16 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (NOT DEFINED CLASP_USE_STD_VECTOR)
endif()
configure_file(${header_path}/config.h.in ${CLASP_BINARY_DIR}/clasp/config.h @ONLY)

set(header_temp
set(header
${CLASP_BINARY_DIR}/clasp/config.h
${header_path}/heuristics.h
${header_path}/statistics.h
Expand Down Expand Up @@ -62,10 +62,9 @@ set(header_temp
${header_path}/model_enumerators.h
${header_path}/logic_program_types.h
${header_path}/constraint.h)
LIST(APPEND header ${header_temp})
set(ide_header "Header Files")
source_group("${ide_header}" FILES ${header_temp})
set(header_temp
source_group("${ide_header}" FILES ${header})
set(header_util
${header_path}/util/misc_types.h
${header_path}/util/multi_queue.h
${header_path}/util/left_right_sequence.h
Expand All @@ -74,15 +73,13 @@ set(header_temp
${header_path}/util/indexed_priority_queue.h
${header_path}/util/type_manip.h
${header_path}/util/timer.h)
LIST(APPEND header ${header_temp})
source_group("${ide_header}\\util" FILES ${header_temp})
set(header_temp
source_group("${ide_header}\\util" FILES ${header_util})
set(header_cli
${header_path}/cli/clasp_cli_configs.inl
${header_path}/cli/clasp_cli_options.inl
${header_path}/cli/clasp_output.h
${header_path}/cli/clasp_options.h)
LIST(APPEND header ${header_temp})
source_group("${ide_header}\\cli" FILES ${header_temp})
source_group("${ide_header}\\cli" FILES ${header_cli})

set(src
asp_preprocessor.cpp
Expand Down Expand Up @@ -116,15 +113,14 @@ set(src
if (CLASP_BUILD_WITH_THREADS)
LIST(APPEND src
parallel_solve.cpp)
set(header_temp
set(header_mt
${header_path}/mt/thread.h
${header_path}/mt/mutex.h
${header_path}/mt/parallel_solve.h)
LIST(APPEND header ${header_temp})
source_group("${ide_header}\\mt" FILES ${header_temp})
source_group("${ide_header}\\mt" FILES ${header_mt})
endif()

add_library(libclasp ${header} ${src})
add_library(libclasp ${header} ${header_util} ${header_cli} ${header_mt} ${src})
if (CLASP_BUILD_WITH_THREADS)
target_link_libraries(libclasp PUBLIC Threads::Threads)
endif()
Expand All @@ -139,14 +135,21 @@ endif()
target_include_directories(libclasp PUBLIC
$<BUILD_INTERFACE:${CLASP_SOURCE_DIR}>
$<BUILD_INTERFACE:${CLASP_BINARY_DIR}>
$<INSTALL_INTERFACE:${clasp_include_dest}>)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${clasp_include_dest}>)
target_link_libraries(libclasp PUBLIC libpotassco)
set_target_properties(libclasp PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(libclasp PROPERTIES
OUTPUT_NAME clasp
FOLDER lib)

# installation
if (CLASP_INSTALL_LIB)
install(TARGETS libclasp EXPORT clasp DESTINATION "${clasp_library_dest}")
install(FILES ${header} DESTINATION "${clasp_include_dest}/clasp")
install(TARGETS libclasp EXPORT clasp DESTINATION "${CMAKE_INSTALL_LIBDIR}/${clasp_library_dest}")
install(FILES ${header} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${clasp_include_dest}/clasp")
install(FILES ${header_util} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${clasp_include_dest}/clasp/util")
install(FILES ${header_cli} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${clasp_include_dest}/clasp/cli")
if (header_mt)
install(FILES ${header_mt} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${clasp_include_dest}/clasp/mt")
endif()
endif()

0 comments on commit f139715

Please sign in to comment.