From ce90bd9e83d1e140f8bd12cb07371a4c16a882db Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 16 Jan 2020 14:58:56 -0800 Subject: [PATCH] [cmake] Simplify compile flag handling on Windows Add options/define flags to ngcore, so they are automatically passed on to dependencies --- CMakeLists.txt | 4 ---- cmake/SuperBuild.cmake | 12 ------------ libsrc/core/CMakeLists.txt | 18 +++++++++--------- libsrc/geom2d/CMakeLists.txt | 3 ++- libsrc/occ/CMakeLists.txt | 1 + 5 files changed, 12 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e3ccc70..a4344075 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -215,13 +215,9 @@ endmacro() set(CMAKE_CXX_STANDARD 17) if(WIN32) - get_WIN32_WINNT(ver) - add_definitions(-D_WIN32_WINNT=${ver} -DWNT -DWNT_WINDOW -DNOMINMAX) set(CMAKE_MFC_FLAG 0) - add_definitions(-DMSVC_EXPRESS -D_CRT_SECURE_NO_WARNINGS -DHAVE_STRUCT_TIMESPEC) # build convenience (aka object) libraries in windows) set(NG_LIB_TYPE OBJECT) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") else(WIN32) # build shared libraries set(NG_LIB_TYPE SHARED) diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 36ec058f..a04e4164 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -20,18 +20,6 @@ if(WIN32) set (OCC_DOWNLOAD_URL_WIN "${DEPS_DOWNLOAD_URL}/occ_win64.zip" CACHE STRING INTERNAL) set (TCLTK_DOWNLOAD_URL_WIN "${DEPS_DOWNLOAD_URL}/tcltk_win64.zip" CACHE STRING INTERNAL) set (ZLIB_DOWNLOAD_URL_WIN "${DEPS_DOWNLOAD_URL}/zlib_win64.zip" CACHE STRING INTERNAL) - if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel") - string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_CXX_FLAGS_NEW ${CMAKE_CXX_FLAGS}) - set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_NEW} CACHE STRING "compile flags" FORCE) - string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_CXX_FLAGS_NEW ${CMAKE_CXX_FLAGS_RELEASE}) - set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_NEW} CACHE STRING "compile flags" FORCE) - - string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_SHARED_LINKER_FLAGS_NEW ${CMAKE_SHARED_LINKER_FLAGS}) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_NEW} /IGNORE:4217,4049" CACHE STRING "compile flags" FORCE) - string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_EXE_LINKER_FLAGS_NEW ${CMAKE_EXE_LINKER_FLAGS}) - set(CMAKE_EXE_LINKER_FLAGS"${CMAKE_EXE_LINKER_FLAGS_NEW}/IGNORE:4217,4049" CACHE STRING "compile flags" FORCE) - - endif(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel") endif(WIN32) if(UNIX) diff --git a/libsrc/core/CMakeLists.txt b/libsrc/core/CMakeLists.txt index 5c58e7e6..cb5eb36c 100644 --- a/libsrc/core/CMakeLists.txt +++ b/libsrc/core/CMakeLists.txt @@ -23,21 +23,21 @@ if(USE_PYTHON) target_compile_definitions(ngcore PUBLIC NETGEN_PYTHON NG_PYTHON) endif(USE_PYTHON) -target_compile_definitions(ngcore PRIVATE NGCORE_EXPORTS) -if(NOT WIN32) - target_compile_options(ngcore PRIVATE -fvisibility=hidden) -endif(NOT WIN32) - if(WIN32) - target_compile_options(ngcore PUBLIC /bigobj) + target_compile_options(ngcore PUBLIC /bigobj /MP /W1 /wd4068) + get_WIN32_WINNT(ver) + target_compile_definitions(ngcore PUBLIC _WIN32_WINNT=${ver} WNT WNT_WINDOW NOMINMAX MSVC_EXPRESS _CRT_SECURE_NO_WARNINGS HAVE_STRUCT_TIMESPEC) + target_link_options(ngcore PUBLIC /ignore:4273 /ignore:4217 /ignore:4049) +else(WIN32) + target_compile_options(ngcore PRIVATE -fvisibility=hidden) endif(WIN32) -target_compile_definitions(ngcore PUBLIC $<$:NETGEN_ENABLE_CHECK_RANGE>) +target_compile_definitions(ngcore PRIVATE NGCORE_EXPORTS) target_include_directories(ngcore INTERFACE $ $) -if(CHECK_RANGE) +if(CHECK_RANGE OR CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG") target_compile_definitions(ngcore PUBLIC NETGEN_ENABLE_CHECK_RANGE) -endif(CHECK_RANGE) +endif(CHECK_RANGE OR CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG") if(USE_SPDLOG) include_directories(${SPDLOG_INCLUDE_DIR}) diff --git a/libsrc/geom2d/CMakeLists.txt b/libsrc/geom2d/CMakeLists.txt index ab292315..f496448d 100644 --- a/libsrc/geom2d/CMakeLists.txt +++ b/libsrc/geom2d/CMakeLists.txt @@ -11,8 +11,9 @@ endif(NOT WIN32) if(USE_GUI) add_library(geom2dvis ${NG_LIB_TYPE} vsgeom2d.cpp) + target_link_libraries(geom2dvis PUBLIC ngcore) if(NOT WIN32) - target_link_libraries(geom2dvis geom2d) + target_link_libraries(geom2dvis PUBLIC geom2d) install( TARGETS geom2dvis ${NG_INSTALL_DIR}) endif(NOT WIN32) endif(USE_GUI) diff --git a/libsrc/occ/CMakeLists.txt b/libsrc/occ/CMakeLists.txt index 39da5a89..7e7a2a65 100644 --- a/libsrc/occ/CMakeLists.txt +++ b/libsrc/occ/CMakeLists.txt @@ -6,6 +6,7 @@ add_library(occ ${NG_LIB_TYPE} ) if(USE_GUI) add_library(occvis ${NG_LIB_TYPE} vsocc.cpp) + target_link_libraries(occvis PUBLIC ngcore) endif(USE_GUI) target_link_libraries(occ PUBLIC ngcore PRIVATE netgen_python)