Skip to content

Commit c95a703

Browse files
author
AndreaCasalino
committed
better cmake
1 parent 67c5e51 commit c95a703

File tree

5 files changed

+11
-144
lines changed

5 files changed

+11
-144
lines changed

CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ option(LIB_OPT "Compile shared libraries (ON) or static (OFF)" OFF)
44

55
set(CMAKE_CXX_STANDARD 17)
66

7-
# set macro-directory and find scripts
8-
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
9-
10-
# include cmake custom functions
11-
set(WITH_SOURCE_TREE ON)
12-
include(GroupSources)
13-
include(AutoCollect)
14-
include(MakeLibrary)
7+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/MakeLibrary.cmake)
158

169
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
1710

Lib/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ if(ENABLE_XML_Parser_nlohmann_json_converter)
1313
ENABLE_XML_Parser_nlohmann_json_converter
1414
)
1515

16+
17+
if (NOT TARGET nlohmann_json::nlohmann_json)
1618
include(FetchContent)
1719
FetchContent_Declare(
1820
json_lib
1921
GIT_REPOSITORY https://github.com/nlohmann/json.git
2022
GIT_TAG v3.10.5
2123
)
2224
FetchContent_MakeAvailable(json_lib)
25+
endif()
2326

2427
target_link_libraries(${PROJECT_SHORTNAME} PUBLIC
2528
nlohmann_json::nlohmann_json

cmake/AutoCollect.cmake

Lines changed: 0 additions & 82 deletions
This file was deleted.

cmake/GroupSources.cmake

Lines changed: 0 additions & 49 deletions
This file was deleted.

cmake/MakeLibrary.cmake

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
function(MakeLibrary LIBRARY_NAME INCLUDE_DIR)
2-
CollectSourceFiles(${CMAKE_CURRENT_SOURCE_DIR} SOURCES)
3-
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
2+
file(GLOB_RECURSE SOURCES
3+
${CMAKE_CURRENT_SOURCE_DIR}/*.h
4+
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
5+
)
46

57
if(LIB_OPT)
68
if (WIN32)
@@ -12,11 +14,11 @@ else()
1214
add_library(${LIBRARY_NAME} STATIC ${SOURCES})
1315
endif()
1416

15-
target_include_directories(${LIBRARY_NAME}
16-
PUBLIC
17-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_DIR}>
17+
target_include_directories(${LIBRARY_NAME} PUBLIC
18+
${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_DIR}
1819
)
1920

2021
install(TARGETS ${LIBRARY_NAME})
2122
install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_DIR}/ DESTINATION include/${LIBRARY_NAME} FILES_MATCHING PATTERN "*.h*")
2223
endfunction()
24+

0 commit comments

Comments
 (0)