@@ -17,23 +17,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
17
17
set (CMAKE_CXX_EXTENSIONS OFF )
18
18
set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
19
19
20
- # Add an external; appends to `PYTHONMONKEY_EXTERNAL_FILES` in the parent scope.
21
- function (pythonmonkey_add_external PYTHONMONKEY_EXTERNAL)
22
- add_subdirectory ("cmake/externals/${PYTHONMONKEY_EXTERNAL} " )
23
- set (PYTHONMONKEY_EXTERNAL_FILE "cmake/externals/${PYTHONMONKEY_EXTERNAL} /CMakeLists.txt" )
24
- source_group (
25
- TREE "${CMAKE_CURRENT_SOURCE_DIR} /cmake/externals/${PYTHONMONKEY_EXTERNAL} "
26
- PREFIX "Externals\\ ${PYTHONMONKEY_EXTERNAL} "
27
- FILES "${PYTHONMONKEY_EXTERNAL_FILE} "
28
- )
29
- list (APPEND PYTHONMONKEY_EXTERNAL_FILES "${PYTHONMONKEY_EXTERNAL_FILE} " )
30
-
31
- set (PYTHONMONKEY_EXTERNAL_FILES ${PYTHONMONKEY_EXTERNAL_FILES} PARENT_SCOPE)
32
- endfunction ()
33
-
34
- file (GLOB SOURCE_FILES "src/*.cc" "src/internalBinding/*.cc" ) # Find all C++ files in the src directory
35
- file (GLOB HEADER_FILES "include/*.hh" ) # Find all header files in the include directory
36
- file (GLOB PYTHON_FILES "python/*.cc" "python/*.hh" ) # Find all the python bindings in the python directory
20
+ file (GLOB_RECURSE HEADER_FILES "include/*.hh" ) # Find all header files in the include directory and below
21
+ file (GLOB_RECURSE SOURCE_FILES "src/*.cc" ) # Find all C++ files in the src directory and below
22
+
37
23
38
24
include_directories (${CMAKE_CURRENT_LIST_DIR} )
39
25
@@ -43,8 +29,50 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
43
29
### Code block from: https://cliutils.gitlab.io/modern-cmake/chapters/projects/submodule.html
44
30
include (FetchContent)
45
31
46
- SET (COMPILE_FLAGS "-ggdb -Ofast -fno-rtti" ) # optimize but also emit debug symbols
47
- SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS} $ENV{EXTRA_CMAKE_CXX_FLAGS} " )
32
+ if (WIN32 )
33
+ SET (COMPILE_FLAGS "/GR- /W0" )
34
+
35
+ SET (OPTIMIZED "/O2" )
36
+ SET (UNOPTIMIZED "/Od" )
37
+ SET (KEEP_SYMBOLS "/DEBUG:FULL" )
38
+ SET (STRIP_SYMBOLS "/DEBUG:NONE" )
39
+ SET (PROFILE "/PROFILE" )
40
+ else ()
41
+ SET (COMPILE_FLAGS "-fno-rtti -Wno-invalid-offsetof" )
42
+
43
+ SET (OPTIMIZED "-Ofast -DNDEBUG" )
44
+ SET (UNOPTIMIZED "-O0" )
45
+ SET (KEEP_SYMBOLS "-ggdb" )
46
+ SET (STRIP_SYMBOLS "-s" )
47
+ SET (PROFILE "-pg" )
48
+ endif ()
49
+ SET (PROFILE_FLAGS "${UNOPTIMIZED} ${KEEP_SYMBOLS} ${PROFILE} " )
50
+ SET (DEBUG_FLAGS "${UNOPTIMIZED} ${KEEP_SYMBOLS} " )
51
+ SET (DRELEASE_FLAGS "${OPTIMIZED} ${KEEP_SYMBOLS} " )
52
+ SET (RELEASE_FLAGS "${OPTIMIZED} ${STRIP_SYMBOLS} " )
53
+
54
+ if (GENERATOR_IS_MULTI_CONFIG)
55
+ set (CMAKE_CONFIGURATION_TYPES "Profile;Debug;DRelease;Release" CACHE STRING "" FORCE)
56
+ string (APPEND COMPILE_FLAGS "$<$<CONFIG:Profile>:${PROFILE_FLAGS} > $<$<CONFIG:Debug>:${DEBUG_FLAGS} > $<$<CONFIG:DRelease>:${DRELEASE_FLAGS} > $<$<CONFIG:Release>:${RELEASE_FLAGS} >" )
57
+ else ()
58
+ set_property (CACHE PM_BUILD_TYPE PROPERTY HELPSTRING "Choose the type of build" )
59
+ set_property (CACHE PM_BUILD_TYPE PROPERTY STRINGS "Profile;Debug;DRelease;Release" )
60
+ if (PM_BUILD_TYPE STREQUAL "Profile" )
61
+ list (APPEND COMPILE_FLAGS "${PROFILE_FLAGS} " )
62
+ elseif (PM_BUILD_TYPE STREQUAL "Debug" )
63
+ list (APPEND COMPILE_FLAGS "${DEBUG_FLAGS} " )
64
+ elseif (PM_BUILD_TYPE STREQUAL "DRelease" )
65
+ list (APPEND COMPILE_FLAGS "${DRELEASE_FLAGS} " )
66
+ else () #Release build
67
+ message ("PM_BUILD_TYPE not detected or invalid value, defaulting to Release build." )
68
+ set (PM_BUILD_TYPE Release CACHE STRING "" FORCE)
69
+ list (APPEND COMPILE_FLAGS "${RELEASE_FLAGS} " )
70
+ endif ()
71
+ message ("PythonMonkey build type is: ${PM_BUILD_TYPE} " )
72
+ list (JOIN COMPILE_FLAGS " " COMPILE_FLAGS )
73
+ endif ()
74
+
75
+ SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS} " )
48
76
49
77
set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR} /cmake/modules)
50
78
if (APPLE )
@@ -55,36 +83,35 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
55
83
set (PYTHONLIBS_VERSION_STRING ${Python_VERSION} )
56
84
set (PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIRS} )
57
85
set (PYTHON_LIBRARIES ${Python_LIBRARIES} )
58
- message ("Apple - Using Python:${Python_VERSION_MAJOR} - Libraries:${PYTHON_LIBRARIES} - IncludeDirs: ${PYTHON_INCLUDE_DIR} " )
59
86
elseif (UNIX )
60
87
find_package (Python 3.8 COMPONENTS Interpreter Development REQUIRED)
61
88
set (Python_FIND_VIRTUALENV FIRST) # (require cmake >= v3.15 and this is the default) use the Python version configured by pyenv if available
62
89
set (PYTHON_LIBRARIES ${Python_LIBRARIES} )
63
90
set (PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIRS} )
64
- message ("Linux - Using Python:${Python_VERSION_MAJOR} .${Python_VERSION_MINOR} - Libraries:${PYTHON_LIBRARIES} - IncludeDirs: ${PYTHON_INCLUDE_DIR} " )
65
91
find_package (SpiderMonkey REQUIRED)
66
92
elseif (WIN32 )
67
- find_package (PythonInterp 3.8 REQUIRED)
68
- find_package (PythonLibs 3.8 REQUIRED)
93
+ find_package (Python 3.8 COMPONENTS Interpreter Development REQUIRED)
94
+ set (Python_FIND_VIRTUALENV FIRST) # (require cmake >= v3.15 and this is the default) use the Python version configured by pyenv if available
95
+ set (PYTHON_LIBRARIES ${Python_LIBRARIES} )
96
+ set (PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIRS} )
69
97
find_package (SpiderMonkey REQUIRED)
70
- set (PYTHONLIBS_VERSION_STRING $ENV{PY_VERSION} )
71
98
endif ()
72
- include_directories (${PYTHON_INCLUDE_DIRS} )
99
+ message ("${CMAKE_SYSTEM_NAME} - Using Python:${Python_VERSION} - Libraries:${Python_LIBRARIES} - IncludeDirs: ${Python_INCLUDE_DIRS} " )
100
+ include_directories (${Python_INCLUDE_DIRS} )
73
101
include_directories (${SPIDERMONKEY_INCLUDE_DIR} )
74
102
75
103
# Add doxygen if this is the main app
76
- find_package (Doxygen)
77
- if (Doxygen_FOUND)
104
+ option (BUILD_DOCS "Build documentation" OFF )
105
+ if (BUILD_DOCS)
106
+ find_package (Doxygen)
107
+ if (Doxygen_FOUND)
78
108
add_subdirectory (cmake/docs)
79
- else ()
109
+ else ()
80
110
message (STATUS "Doxygen not found. Not building docs." )
111
+ endif ()
81
112
endif ()
82
113
83
114
endif ()
84
115
85
116
# Add compiled folder directories
86
117
add_subdirectory (src)
87
-
88
- pythonmonkey_add_external("uncrustify" )
89
- pythonmonkey_add_external("autopep8" )
90
- add_subdirectory (cmake/format)
0 commit comments