1
- cmake_minimum_required (VERSION 3.10)
1
+ cmake_minimum_required (VERSION 3.15...3.27)
2
+ project (${SKBUILD_PROJECT_NAME} LANGUAGES CXX)
2
3
3
- # Project `Name` and `Language`
4
- project (GOSDT)
4
+ set (CMAKE_CXX_STANDARD 20)
5
5
6
- # Set the language standard to `c++11`
7
- set (CMAKE_CXX_STANDARD 11 )
6
+ set ( TARGET "_libgosdt" )
7
+ set (CLI_TARGET "gosdt_cli" )
8
8
9
- # Set the compiler flags
10
- if (MSVC )
11
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} " )
12
- set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /DDEBUG" )
13
- set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} " )
9
+ message (STATUS "PATH environment variable: $ENV{PATH} " )
10
+ message (STATUS "LD_LIBRARY_PATH environment variable: $ENV{LD_LIBRARY_PATH} " )
14
11
15
- # `#define NOMINMAX` prevents expansion of min and max macros on Windows,
16
- # otherwise `std::numeric_limits<T>::max()/min()` leads to MSVC compiler errors.
17
- # Reference: https://stackoverflow.com/questions/27442885/syntax-error-with-stdnumeric-limitsmax
18
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /w /DNOMINMAX" )
19
- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /DDEBUG" )
20
- set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} " )
21
- else ()
22
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra" )
23
- set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -DDEBUG" )
24
- set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} " )
12
+ # Python Target
13
+ if (SKBUILD)
14
+ # Find the module development requirements (requires FindPython from 3.17 or
15
+ # scikit-build-core's built-in backport)
16
+ find_package (Python REQUIRED COMPONENTS Interpreter Development.Module)
17
+ find_package (pybind11 CONFIG REQUIRED)
25
18
26
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" )
27
- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -DDEBUG" )
28
- set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} " )
29
- endif ()
19
+ # Python Target
20
+ file (GLOB_RECURSE SOURCE_FILES src/libgosdt/src/*.cpp src/libgosdt.cpp)
21
+ python_add_library(${TARGET} MODULE ${SOURCE_FILES} WITH_SOABI)
22
+ target_link_libraries (${TARGET} PRIVATE pybind11::module)
23
+ target_include_directories (${TARGET} PUBLIC src/libgosdt/include /)
24
+ install (TARGETS ${TARGET} DESTINATION ${SKBUILD_PROJECT_NAME} )
30
25
31
- #
32
- # MARK: - Targets
33
- #
26
+ # In the case where wer're running on Windows with packages installed via vcpkg, we include
27
+ # the vcpkg.cmake file to find the packages.
28
+ if (WIN32 )
29
+ include ($ENV{VCPKG_INSTALLATION_ROOT} /scripts/buildsystems/vcpkg.cmake)
30
+ endif ()
34
31
35
- # Target Definition
36
- set (TARGET_CLI "gosdt" )
37
- set (TARGET_TESTS "gosdt_tests" )
38
- set (TARGET_PYTHON "libgosdt" )
39
-
40
- # Target: GOSDT CLI
41
- file (GLOB_RECURSE SOURCE_FILES_CLI src/*.cpp)
42
- list (REMOVE_ITEM SOURCE_FILES_CLI "${CMAKE_SOURCE_DIR} /src/python_extension.cpp" )
43
- add_executable (${TARGET_CLI} ${SOURCE_FILES_CLI} )
44
- target_include_directories (${TARGET_CLI} PUBLIC ${CMAKE_SOURCE_DIR} /include )
32
+ endif ()
45
33
46
- # Target: GOSDT Tests
47
- file (GLOB_RECURSE SOURCE_FILES_TESTS src/*.cpp)
48
- list (REMOVE_ITEM SOURCE_FILES_TESTS "${CMAKE_SOURCE_DIR} /src/python_extension.cpp" )
49
- list (REMOVE_ITEM SOURCE_FILES_TESTS "${CMAKE_SOURCE_DIR} /src/main.cpp" )
50
- list (INSERT SOURCE_FILES_TESTS 0 "${CMAKE_SOURCE_DIR} /test/test.cpp" )
51
- add_executable (${TARGET_TESTS} ${SOURCE_FILES_TESTS} )
52
- target_include_directories (${TARGET_TESTS} PUBLIC ${CMAKE_SOURCE_DIR} /include )
34
+ # CLI Target
35
+ file (GLOB_RECURSE SOURCE_FILES src/libgosdt/src/*.cpp src/cli.cpp)
36
+ add_executable (${CLI_TARGET} ${SOURCE_FILES} )
37
+ target_include_directories (${CLI_TARGET} PUBLIC src/libgosdt/include /)
53
38
54
39
#
55
- # MARK: - Dependencies
40
+ # Link all needed dependencies to this project:
56
41
#
42
+ find_package (PkgConfig REQUIRED)
43
+ include (FetchContent)
57
44
58
- # Dependencies: Intel TBB
45
+ # TBB:
59
46
find_package (TBB REQUIRED)
60
- target_link_libraries (${TARGET_CLI} PRIVATE TBB::tbb)
61
- target_link_libraries (${TARGET_CLI} PRIVATE TBB::tbbmalloc)
62
- target_link_libraries (${TARGET_TESTS} PRIVATE TBB::tbb)
63
- target_link_libraries (${TARGET_TESTS} PRIVATE TBB::tbbmalloc)
47
+ if (SKBUILD)
48
+ target_link_libraries (${TARGET} PRIVATE TBB::tbb)
49
+ target_link_libraries (${TARGET} PRIVATE TBB::tbbmalloc)
50
+ endif ()
51
+ target_link_libraries (${CLI_TARGET} PRIVATE TBB::tbb TBB::tbbmalloc)
64
52
65
- # Dependencies: GMP
66
- find_package (PkgConfig REQUIRED)
53
+ # GMP:
67
54
pkg_check_modules(GMP REQUIRED IMPORTED_TARGET gmp)
68
- target_link_libraries (${TARGET_CLI} PRIVATE PkgConfig::GMP)
69
- target_include_directories (${TARGET_CLI} PRIVATE ${GMP_INCLUDE_DIRS} )
70
- target_link_libraries (${TARGET_TESTS} PRIVATE PkgConfig::GMP)
71
- target_include_directories (${TARGET_TESTS} PRIVATE ${GMP_INCLUDE_DIRS} )
72
-
73
- # Dependencies: Threads (pthread on macOS and Ubuntu, win32 thread on Windows)
74
- # This is needed because the CentOS docker provided by manylinux reports linker errors
75
- set (THREADS_PREFER_PTHREAD_FLAG ON )
76
- find_package (Threads REQUIRED)
77
- target_link_libraries (${TARGET_CLI} PRIVATE Threads::Threads)
78
- target_link_libraries (${TARGET_TESTS} PRIVATE Threads::Threads)
55
+ if (SKBUILD)
56
+ target_link_libraries (${TARGET} PRIVATE PkgConfig::GMP)
57
+ target_include_directories (${TARGET} PRIVATE ${GMP_INCLUDE_DIRS} )
58
+ endif ()
59
+ target_link_libraries (${CLI_TARGET} PRIVATE PkgConfig::GMP)
60
+ target_include_directories (${CLI_TARGET} PRIVATE ${GMP_INCLUDE_DIRS} )
79
61
80
- # Target: GOSDT Python Module
62
+ # nlohmann::json:
63
+ FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
64
+ FetchContent_MakeAvailable(json)
81
65
if (SKBUILD)
82
- message (STATUS "GOSDT is built using scikit-build. Will build the Python module." )
83
- # Find the Python 3 development environment
84
- if (NOT DEFINED Python3_INCLUDE_DIR)
85
- message (FATAL_ERROR "The CMake variable Python3_INCLUDE_DIR should have been defined by scikit-build." )
86
- endif ()
87
- # Create the list of source files needed to build the Python extension
88
- file (GLOB_RECURSE SOURCE_FILES_PY src/*.cpp)
89
- list (REMOVE_ITEM SOURCE_FILES_PY "${CMAKE_SOURCE_DIR} /src/main.cpp" )
90
- # Define the CMake target for the Python extension
91
- add_library (${TARGET_PYTHON} MODULE ${SOURCE_FILES_PY} )
92
- target_include_directories (${TARGET_PYTHON} PRIVATE ${CMAKE_SOURCE_DIR} /include ${Python3_INCLUDE_DIR} ${GMP_INCLUDE_DIRS} )
93
- target_link_libraries (${TARGET_PYTHON} TBB::tbb TBB::tbbmalloc PkgConfig::GMP Threads::Threads)
94
- # Set up the Python extension
95
- find_package (PythonExtensions REQUIRED)
96
- ## Use the suffix `.abi3.so` or `.pyd` so that Python 3 on other platforms can find the dylib and import it properly
97
- message (STATUS "The current Python extension suffix is \" ${PYTHON_EXTENSION_MODULE_SUFFIX} \" ." )
98
- if (WIN32 )
99
- set (PYTHON_EXTENSION_MODULE_SUFFIX ".pyd" )
100
- else ()
101
- set (PYTHON_EXTENSION_MODULE_SUFFIX ".abi3.so" )
102
- endif ()
103
- message (STATUS "The new Python extension suffix is \" ${PYTHON_EXTENSION_MODULE_SUFFIX} \" ." )
104
- ## Define the Python extension module target
105
- python_extension_module(${TARGET_PYTHON} )
106
- # Install `libgosdt` to the root directory of the Python extension package
107
- install (TARGETS ${TARGET_PYTHON} LIBRARY DESTINATION .)
66
+ target_link_libraries (${TARGET} PRIVATE nlohmann_json::nlohmann_json)
108
67
endif ()
68
+ target_link_libraries (${CLI_TARGET} PRIVATE nlohmann_json::nlohmann_json)
69
+
70
+ # Generate compile_commands.json for vscode
71
+ set (CMAKE_EXPORT_COMPILE_COMMANDS
72
+ ON
73
+ CACHE INTERNAL "" )
0 commit comments