-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
101 lines (74 loc) · 3.92 KB
/
CMakeLists.txt
File metadata and controls
101 lines (74 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
cmake_minimum_required(VERSION 3.25.1 FATAL_ERROR)
project(CMAKEEXAMPLE VERSION 1.0)
include(CTest)
include(GNUInstallDirs)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(DOWNLOAD_3rdPARTY_LIBS ${CMAKE_SOURCE_DIR}/libs3rdParty/download)
set(BUILD_3rdPARTY_LIBS ${CMAKE_SOURCE_DIR}/libs3rdParty/build)
set(INSTALL_3rdPARTY_LIBS ${CMAKE_SOURCE_DIR}/libs3rdParty/install)
set(RAPIDCSV rapidcsv_FilterSort)
set(CXXARGsOPTS cxxopts)
set(CPPPROPERTIES cppproperties_RecVar)
set(GOOGLETEST googletest)
# The way that CLion manages multiple configurations, it causes a copy of
# the CMakeCache.txt to be copied across due to it not expecting there to
# be a project within a project. This causes the hard-coded paths in the
# cache to be copied and builds to fail. To mitigate this, we simply
# remove the cache if it exists before we configure the new project. It
# is safe to do so because it will be re-generated. Since this is only
# executed at the configure step, it should not cause additional builds or
# downloads.
file(REMOVE "${DOWNLOAD_3rdPARTY_LIBS}/CMakeCache.txt")
# Create and build a separate CMake project to carry out the download.
# If we've already previously done these steps, they will not cause
# anything to be updated, so extra rebuilds of the project won't occur.
# Make sure to pass through CMAKE_MAKE_PROGRAM in case the main project
# has this set to something not findable on the PATH.
configure_file("${CMAKE_CURRENT_LIST_DIR}/DependenciesBuild.cmake.in"
"${DOWNLOAD_3rdPARTY_LIBS}/CMakeLists.txt"
@ONLY
)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
-D "CMAKE_MAKE_PROGRAM:FILE=${CMAKE_MAKE_PROGRAM}"
.
RESULT_VARIABLE result
#${OUTPUT_QUIET}
WORKING_DIRECTORY "${DOWNLOAD_3rdPARTY_LIBS}"
)
if(result)
message(FATAL_ERROR "CMake step for ${PROJECT_NAME} failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
#${OUTPUT_QUIET}
WORKING_DIRECTORY "${DOWNLOAD_3rdPARTY_LIBS}"
)
if(result)
message(FATAL_ERROR "Build step for ${PROJECT_NAME} failed: ${result}")
endif()
set(cxxopts_DIR ${INSTALL_3rdPARTY_LIBS}/lib/cmake/cxxopts)
find_package(cxxopts 3.0.0 REQUIRED)
set(cppproperties_DIR ${INSTALL_3rdPARTY_LIBS}/lib/cmake/cppproperties)
find_package(cppproperties 2.0.01.0 REQUIRED)
# add the executable
add_executable(cmakeExampleExternalProjectAdd main.cxx)
add_library(rapidcsv INTERFACE IMPORTED)
#NOTE : 'cxxopts' doesnot call export(...), hence `find_package(cxxopts... /lib/cmake/cxxopts)`
# behavior is different from that of `find_package(cppproperties... /lib)`
add_library(cxxopts INTERFACE IMPORTED)
# Prevent GoogleTest from overriding our compiler/linker options
# when building with Visual Studio
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(${DOWNLOAD_3rdPARTY_LIBS}/${GOOGLETEST} ${BUILD_3rdPARTY_LIBS}/${GOOGLETEST})
add_dependencies(cmakeExampleExternalProjectAdd rapidcsv cxxopts cppproperties)
target_include_directories(cmakeExampleExternalProjectAdd
PUBLIC ${PROJECT_BINARY_DIR}
PRIVATE ${INSTALL_3rdPARTY_LIBS}/include
)
target_link_directories(cmakeExampleExternalProjectAdd PRIVATE ${INSTALL_3rdPARTY_LIBS}/lib)
target_link_libraries(cmakeExampleExternalProjectAdd INTERFACE rapidcsv cxxopts)
target_link_libraries(cmakeExampleExternalProjectAdd PRIVATE cppproperties gtest gmock_main)
# add the install targets
install(TARGETS cmakeExampleExternalProjectAdd DESTINATION bin)
add_test(NAME example_test COMMAND cmakeExampleExternalProjectAdd --propfilename=${CMAKE_CURRENT_LIST_DIR}/property/test1.txt)