8000 Update CMake system · ChaiScript/ChaiScript_Extras@b0da797 · GitHub
[go: up one dir, main page]

Skip to content

Commit b0da797

Browse files
committed
Update CMake system
1 parent 961b3dd commit b0da797

File tree

6 files changed

+104
-73
lines changed

6 files changed

+104
-73
lines changed

CMakeLists.txt

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 2.8)
1+
cmake_minimum_required(VERSION 3.11) # FetchContent requires CMake 3.11
22
project(chaiscript_extras)
33

44
if(BIICODE)
@@ -15,7 +15,6 @@ endif()
1515

1616
option(BUILD_IN_CPP17_MODE "Build with C++17 flags" FALSE)
1717

18-
1918
if(CMAKE_COMPILER_IS_GNUCC)
2019
option(ENABLE_COVERAGE "Enable Coverage Reporting in GCC" FALSE)
2120

@@ -76,8 +75,6 @@ endif()
7675
include(CTest)
7776
enable_testing()
7877

79-
80-
8178
if(CMAKE_COMPILER_IS_GNUCC)
8279
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
8380

@@ -142,7 +139,6 @@ if(MINGW OR CYGWIN)
142139
add_definitions(-O3)
143140
endif()
144141

145-
146142
if(NOT MULTITHREAD_SUPPORT_ENABLED)
147143
add_definitions(-DCHAISCRIPT_NO_THREADS)
148144
endif()
@@ -166,75 +162,11 @@ if(CMAKE_HOST_UNIX)
166162

167163
add_definitions(-pthread)
168164
endif()
169-
170165
endif()
171166

172-
list(APPEND LIBS ${READLINE_LIB})
173-
174167
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
175168
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
176169
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
177170

178-
# ChaiScript
179-
set(CHAISCRIPT_BRANCH v5.8.6)
180-
set(CHAISCRIPT_VERSION 5.8.6)
181-
file(DOWNLOAD https://github.com/ChaiScript/ChaiScript/archive/${CHAISCRIPT_BRANCH}.tar.gz "${CMAKE_BINARY_DIR}/chaiscript/chaiscript-${CHAISCRIPT_BRANCH}.tar.gz"
182-
INACTIVITY_TIMEOUT 180 TIMEOUT 180 TLS_VERIFY off)
183-
execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xf "${CMAKE_BINARY_DIR}/chaiscript/chaiscript-${CHAISCRIPT_BRANCH}.tar.gz" "${CMAKE_BINARY_DIR}/chaiscript"
184-
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/chaiscript")
185-
include_directories("${CMAKE_BINARY_DIR}/chaiscript/ChaiScript-${CHAISCRIPT_VERSION}/include")
186-
187-
# String ID
188-
set(STRING_ID_VERSION 674527b0dab0cca9cf846f3084e986d2783357eb)
189-
file(DOWNLOAD https://github.com/foonathan/string_id/archive/${STRING_ID_VERSION}.tar.gz "${CMAKE_BINARY_DIR}/string_id/string_id-${STRING_ID_VERSION}.tar.gz"
190-
INACTIVITY_TIMEOUT 180 TIMEOUT 180 TLS_VERIFY off)
191-
execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xf "${CMAKE_BINARY_DIR}/string_id/string_id-${STRING_ID_VERSION}.tar.gz" "${CMAKE_BINARY_DIR}/string_id"
192-
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/string_id")
193-
file(RENAME "${CMAKE_BINARY_DIR}/string_id/string_id-${STRING_ID_VERSION}" "${CMAKE_BINARY_DIR}/string_id/string_id")
194-
include_directories("${CMAKE_BINARY_DIR}/string_id")
195-
include_directories("${CMAKE_SOURCE_DIR}/tests")
196-
197-
# Add catch tests macro
198-
macro(ADD_CATCH_TESTS executable)
199-
if (MSVC)
200-
file(TO_NATIVE_PATH "${QT_LIBRARY_DIR}" QT_LIB_PATH)
201-
set(NEWPATH "${QT_LIB_PATH};$ENV{PATH}")
202-
else()
203-
set(NEWPATH $ENV{PATH})
204-
endif()
205-
206-
get_target_property(target_files ${executable} SOURCES)
207-
208-
message("Files: ${target_files}")
209-
210-
foreach(source ${target_files})
211-
if(NOT "${source}" MATCHES "/moc_.*cxx")
212-
string(REGEX MATCH .*cpp source "${source}")
213-
if(source)
214-
file(READ "${source}" contents)
215-
string(REGEX MATCHALL "TEST_CASE\\([ ]*\"[^\"]+\"" found_tests ${contents})
216-
foreach(hit ${found_tests})
217-
message("Found Test: ${hit}")
218-
string(REGEX REPLACE "TEST_CASE\\([ ]*(\"[^\"]+\").*" "\\1" test_name ${hit})
219-
add_test(${test_name} "${executable}" ${test_name})
220-
set_tests_properties(${test_name} PROPERTIES TIMEOUT 660 ENVIRONMENT "PATH=${NEWPATH}")
221-
endforeach()
222-
endif()
223-
endif()
224-
endforeach()
225-
endmacro()
226-
227-
228-
229-
add_executable(math_test tests/math.cpp)
230-
target_link_libraries(math_test ${LIBS})
231-
ADD_CATCH_TESTS(math_test)
232-
233-
# TODO: Fix String ID Tests
234-
#add_executable(string_id_test tests/string_id.cpp)
235-
#target_link_libraries(string_id_test ${LIBS})
236-
#ADD_CATCH_TESTS(string_id_test)
237-
238-
add_executable(string_methods_test tests/string_methods.cpp)
239-
target_link_libraries(string_methods_test ${LIBS})
240-
ADD_CATCH_TESTS(string_methods_test)
171+
add_subdirectory(cmake)
172+
add_subdirectory(tests)

cmake/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include(chaiscript.cmake)
2+
3+
# TODO: Fix string_id_test.
4+
#include(foonathan_string_id.cmake)

cmake/chaiscript.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
set(CHAISCRIPT_VERSION 5.8.6)
2+
find_package(chaiscript ${CHAISCRIPT_VERSION} QUIET)
3+
4+
if (NOT chaiscript_FOUND)
5+
include(FetchContent)
6+
7+
FetchContent_Declare(
8+
chaiscript
9+
GIT_REPOSITORY https://github.com/ChaiScript/ChaiScript.git
10+
GIT_TAG v${CHAISCRIPT_VERSION}
11+
)
12+
13+
FetchContent_GetProperties(chaiscript)
14+
if (NOT chaiscript_POPULATED)
15+
set(FETCHCONTENT_QUIET NO)
16+
FetchContent_Populate(chaiscript)
17+
18+
set(BUILD_SAMPLES OFF CACHE BOOL "" FORCE)
19+
set(BUILD_MODULES ON CACHE BOOL "" FORCE)
20+
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
21+
set(BUILD_LIBFUZZ_TESTER OFF CACHE BOOL "" FORCE)
22+
23+
add_subdirectory(${chaiscript_SOURCE_DIR} ${chaiscript_BINARY_DIR})
24+
endif()
25+
endif()

cmake/foonathan_string_id.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set(STRING_ID_VERSION 6e2e5c48ee4a3ac0c54ba505f0a573561f2979ec)
2+
find_package(foonathan_string_id 2.0.3 QUIET)
3+
4+
if (NOT foonathan_string_id_FOUND)
5+
include(FetchContent)
6+
7+
FetchContent_Declare(
8+
foonathan_string_id
9+
GIT_REPOSITORY https://github.com/foonathan/string_id.git
10+
GIT_TAG ${STRING_ID_VERSION}
11+
)
12+
13+
FetchContent_GetProperties(foonathan_string_id)
14+
if (NOT foonathan_string_id_POPULATED)
15+
set(FETCHCONTENT_QUIET NO)
16+
FetchContent_Populate(foonathan_string_id)
17+
18+
add_subdirectory(${foonathan_string_id_SOURCE_DIR} ${foonathan_string_id_BINARY_DIR})
19+
endif()
20+
endif()

include/chaiscript/extras/string_id.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include <string_id/database.hpp>
1010
#include <string_id/basic_database.hpp>
1111

12-
13-
1412
namespace chaiscript {
1513
namespace extras {
1614
namespace string_id {

tests/CMakeLists.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
list(APPEND LIBS ${READLINE_LIB})
2+
3+
# Add catch tests macro
4+
macro(ADD_CATCH_TESTS executable)
5+
if (MSVC)
6+
file(TO_NATIVE_PATH "${QT_LIBRARY_DIR}" QT_LIB_PATH)
7+
set(NEWPATH "${QT_LIB_PATH};$ENV{PATH}")
8+
else()
9+
set(NEWPATH $ENV{PATH})
10+
endif()
11+
12+
get_target_property(target_files ${executable} SOURCES)
13+
14+
message("Files: ${target_files}")
15+
16+
foreach(source ${target_files})
17+
if(NOT "${source}" MATCHES "/moc_.*cxx")
18+
string(REGEX MATCH .*cpp source "${source}")
19+
if(source)
20+
file(READ "${source}" contents)
21+
string(REGEX MATCHALL "TEST_CASE\\([ ]*\"[^\"]+\"" found_tests ${contents})
22+
foreach(hit ${found_tests})
23+
message("Found Test: ${hit}")
24+
string(REGEX REPLACE "TEST_CASE\\([ ]*(\"[^\"]+\").*" "\\1" test_name ${hit})
25+
add_test(${test_name} "${executable}" ${test_name})
26+
set_tests_properties(${test_name} PROPERTIES TIMEOUT 660 ENVIRONMENT "PATH=${NEWPATH}")
27+
endforeach()
28+
endif()
29+
endif()
30+
endforeach()
31+
endmacro()
32+
33+
# Math
34+
add_executable(math_test math.cpp)
35+
target_link_libraries(math_test ${LIBS})
36+
target_include_directories(math_test PUBLIC "${chaiscript_SOURCE_DIR}/include")
37+
ADD_CATCH_TESTS(math_test)
38+
39+
# String ID
40+
#add_executable(string_id_test string_id.cpp)
41+
#target_link_libraries(string_id_test ${LIBS} foonathan_string_id)
42+
#target_include_directories(string_id_test PUBLIC
43+
# "${chaiscript_SOURCE_DIR}/include"
44+
# "${foonathan_string_id_SOURCE_DIR}"
45+
#)
46+
#ADD_CATCH_TESTS(string_id_test)
47+
48+
# String Methods
49+
add_executable(string_methods_test string_methods.cpp)
50+
target_link_libraries(string_methods_test ${LIBS})
51+
target_include_directories(string_methods_test PUBLIC "${chaiscript_SOURCE_DIR}/include")
52+
ADD_CATCH_TESTS(string_methods_test)

0 commit comments

Comments
 (0)
0