Refactor CMake listfile to define an interface imported library
Define the library as an interface imported library so other targets can use the library as a dependency and use the interface properties of the library.
This commit is contained in:
parent
3ca1bfdd9d
commit
28f73ed406
1 changed files with 13 additions and 20 deletions
|
@ -2,24 +2,17 @@ cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
project(json CXX)
|
project(json CXX)
|
||||||
|
|
||||||
add_executable(json_unit
|
add_library(${PROJECT_NAME} INTERFACE IMPORTED GLOBAL)
|
||||||
src/json.hpp test/catch.hpp test/unit.cpp
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
)
|
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||||
|
|
||||||
if(MSVC)
|
set(UNIT_TEST_NAME "json_unit")
|
||||||
set(CMAKE_CXX_FLAGS
|
add_executable(${UNIT_TEST_NAME}
|
||||||
"/EHsc"
|
"test/catch.hpp" "test/unit.cpp")
|
||||||
)
|
set_target_properties(${UNIT_TEST_NAME} PROPERTIES
|
||||||
|
CXX_STANDARD 11
|
||||||
STRING(REPLACE "/O2" "/Od" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
|
CXX_STANDARD_REQUIRED ON
|
||||||
|
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
|
||||||
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
|
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>")
|
||||||
else(MSVC)
|
target_include_directories(${UNIT_TEST_NAME} PRIVATE "test")
|
||||||
set(CMAKE_CXX_FLAGS
|
target_link_libraries(${UNIT_TEST_NAME} ${PROJECT_NAME})
|
||||||
"-std=c++11"
|
|
||||||
)
|
|
||||||
endif(MSVC)
|
|
||||||
|
|
||||||
include_directories(
|
|
||||||
src test
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in a new issue