From 96e1b2c157398a441b0a76ead9b7e40a0100beff Mon Sep 17 00:00:00 2001 From: Michele Adduci Date: Mon, 11 Jan 2021 06:59:32 +0100 Subject: [PATCH] Fixed issue with compiler options --- CMakeLists.txt | 2 +- cmake/compiler_options.cmake | 5 +---- cmake/dependencies.cmake | 1 - examples/CMakeLists.txt | 7 +++++++ tests/template/CMakeLists.txt | 3 +-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd9b8c6d2..eb90d09d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,8 @@ option(BUILD_TESTING "Builds the tests in the project" OFF) ##################################### # Define CMake Module Imports ##################################### -include(${CMAKE_SOURCE_DIR}/cmake/compiler_options.cmake) include(${CMAKE_SOURCE_DIR}/cmake/dependencies.cmake) +include(${CMAKE_SOURCE_DIR}/cmake/compiler_options.cmake) ##################################### # Define project-wide imports diff --git a/cmake/compiler_options.cmake b/cmake/compiler_options.cmake index 1646e16fd..1aa987894 100644 --- a/cmake/compiler_options.cmake +++ b/cmake/compiler_options.cmake @@ -5,7 +5,7 @@ if(MSVC) list(APPEND compiler_options /W4 /permissive- - $<$:/O2 /Ob2 > + $<$:/O2 /Ob2> $<$:/O1 /Ob1> $<$:/Zi /O2 /Ob1> $<$:/Zi /Ob0 /Od /RTC1>) @@ -23,6 +23,3 @@ else(MSVC) $<$:-pg>) endif() - -# This can also be done with target_compile_options() [recommended] -set(CMAKE_CXX_FLAGS "${compiler_options}") \ No newline at end of file diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index d1c7fce96..bd9b69c77 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -23,7 +23,6 @@ if(BUILD_EXAMPLES OR BUILD_TESTING) if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIR}) endif() - endif() if(BUILD_EXAMPLES) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c8c7deda7..4aaae3ecb 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -9,17 +9,21 @@ list(APPEND REQUIRED_LIBRARIES if (MSVC) add_executable(example_vs example_vs.cpp) + target_compile_options(example_vs PRIVATE "${compiler_options}") target_link_libraries(example_vs ) else () add_executable(helloworld helloworld.cpp) + target_compile_options(helloworld PRIVATE "${compiler_options}") target_link_libraries(helloworld PUBLIC ${REQUIRED_LIBRARIES}) if (OPENSSL_FOUND) add_executable(example_ssl ssl/example_ssl.cpp) + target_compile_options(example_ssl PRIVATE "${compiler_options}") target_link_libraries(example_ssl PUBLIC ${REQUIRED_LIBRARIES} ${OPENSSL_LIBRARIES}) endif() add_executable(example_websocket websocket/example_ws.cpp) + target_compile_options(example_websocket PRIVATE "${compiler_options}") target_link_libraries(example_websocket ) target_link_libraries(example_websocket PUBLIC ${REQUIRED_LIBRARIES}) add_custom_command(OUTPUT ws.html @@ -30,6 +34,7 @@ else () add_custom_target(example_ws_copy ALL DEPENDS ws.html) add_executable(basic_example example.cpp) + target_compile_options(basic_example PRIVATE "${compiler_options}") target_link_libraries(basic_example PUBLIC ${REQUIRED_LIBRARIES}) if (Tcmalloc_FOUND) @@ -38,6 +43,7 @@ else () add_executable(example_with_all example_with_all.cpp) add_dependencies(example_with_all amalgamation) + target_compile_options(example_with_all PRIVATE "${compiler_options}") target_link_libraries(example_with_all PUBLIC ${REQUIRED_LIBRARIES}) add_custom_command(OUTPUT example_test.py @@ -48,6 +54,7 @@ else () add_custom_target(example_copy ALL DEPENDS example_test.py) add_executable(example_chat example_chat.cpp) + target_compile_options(example_chat PRIVATE "${compiler_options}") target_link_libraries(example_chat PUBLIC ${REQUIRED_LIBRARIES}) add_custom_command(OUTPUT example_chat.html diff --git a/tests/template/CMakeLists.txt b/tests/template/CMakeLists.txt index 364d356ae..9b8c1fb89 100644 --- a/tests/template/CMakeLists.txt +++ b/tests/template/CMakeLists.txt @@ -10,8 +10,7 @@ set(TEST_SRCS ) add_executable(mustachetest ${TEST_SRCS}) -set_target_properties(mustachetest PROPERTIES COMPILE_FLAGS "-Wall -Werror -std=c++14") - +target_compile_options(mustachetest PRIVATE "${compiler_options}") file(COPY DIRECTORY . DESTINATION ${CMAKE_CURRENT_BINARY_DIR} FILES_MATCHING PATTERN "*.json") add_custom_command(OUTPUT test.py