From 28f73ed406ec8b4a5d79ea486f92160f844dfb9b Mon Sep 17 00:00:00 2001 From: Robert Marki Date: Sun, 24 Apr 2016 16:55:32 +0200 Subject: [PATCH] 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. --- CMakeLists.txt | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16e9f960..3985171b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,24 +2,17 @@ cmake_minimum_required(VERSION 2.8) project(json CXX) -add_executable(json_unit - src/json.hpp test/catch.hpp test/unit.cpp -) +add_library(${PROJECT_NAME} INTERFACE IMPORTED GLOBAL) +set_target_properties(${PROJECT_NAME} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/src") -if(MSVC) - set(CMAKE_CXX_FLAGS - "/EHsc" - ) - - STRING(REPLACE "/O2" "/Od" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}) - - add_definitions(-D_SCL_SECURE_NO_WARNINGS) -else(MSVC) - set(CMAKE_CXX_FLAGS - "-std=c++11" - ) -endif(MSVC) - -include_directories( - src test -) +set(UNIT_TEST_NAME "json_unit") +add_executable(${UNIT_TEST_NAME} + "test/catch.hpp" "test/unit.cpp") +set_target_properties(${UNIT_TEST_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON + COMPILE_DEFINITIONS "$<$:_SCL_SECURE_NO_WARNINGS>" + COMPILE_OPTIONS "$<$:/EHsc;$<$:/Od>>") +target_include_directories(${UNIT_TEST_NAME} PRIVATE "test") +target_link_libraries(${UNIT_TEST_NAME} ${PROJECT_NAME})