Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMake] Switched to target_compile_options() instead of CXX_FLAGS #2168

Merged
merged 4 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Applications/DataExplorer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}/NetCdfDialog/NetCdfDialogLib_autogen/include
)

set(CMAKE_AUTOMOC TRUE)
set(CMAKE_AUTOUIC TRUE)
set(CMAKE_AUTORCC TRUE)

# Add subprojects
add_subdirectory(Base)
add_subdirectory(DataView/StratView)
Expand Down
11 changes: 6 additions & 5 deletions Applications/Utils/OGSFileConverter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}/OGSFileConverterLib_autogen/include
)

file(GLOB_RECURSE UIS *.ui)
source_group("UI Files" FILES ${UIS})

add_library(OGSFileConverterLib
${SOURCES}
${HEADERS}
${UIS}
)
target_link_libraries(OGSFileConverterLib
PUBLIC QtBase MathLib
Expand All @@ -31,7 +27,12 @@ target_link_libraries(OGSFileConverter
ApplicationsFileIO
)

set_property(TARGET OGSFileConverter PROPERTY FOLDER "Utilities")
set_target_properties(OGSFileConverter OGSFileConverterLib
PROPERTIES
FOLDER "Utilities"
AUTOMOC ON
AUTOUIC ON
)

if(OGS_USE_PCH)
cotire(OGSFileConverter)
Expand Down
4 changes: 3 additions & 1 deletion MathLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ APPEND_SOURCE_FILES(SOURCES InterpolationAlgorithms)
APPEND_SOURCE_FILES(SOURCES Integration)
APPEND_SOURCE_FILES(SOURCES LinAlg)
APPEND_SOURCE_FILES(SOURCES LinAlg/Dense)
APPEND_SOURCE_FILES(SOURCES ODE)
if(CVODE_FOUND)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: What was the warning fixed by this commit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning was about that there were no symbols for the implementation of the solver class. No it is simply not part of the project if cvode is not used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks.

APPEND_SOURCE_FILES(SOURCES ODE)
endif()
APPEND_SOURCE_FILES(SOURCES Nonlinear)

if(OGS_USE_EIGEN)
Expand Down
5 changes: 0 additions & 5 deletions MathLib/ODE/CVodeSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
* http://www.opengeosys.org/project/license
*
*/

#ifdef CVODE_FOUND

#include "CVodeSolver.h"

#include <cassert>
Expand Down Expand Up @@ -362,5 +359,3 @@ CVodeSolver::~CVodeSolver() = default;

} // namespace ODE
} // namespace MathLib

#endif // CVODE_FOUND
2 changes: 1 addition & 1 deletion ThirdParty/vtkdiff
Submodule vtkdiff updated 1 files
+9 −13 CMakeLists.txt
2 changes: 1 addition & 1 deletion scripts/cmake/CCacheSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)

if(COMPILER_IS_CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")
add_compile_options(-Qunused-arguments)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not introduced in this PR, but should we really keep that setting?

-Qunused-arguments

    Do not emit any warnings for unused driver arguments.

Are the warnings caused by ccache?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the clang docu
-Qunused-arguments Don’t emit warning for unused driver arguments

I guess it is silencing the ccache options not used by clang. It was added here, isn't it ;) ?

Feel free to remove the option, if there are not too many warnings because of unused ccache options.

endif()

if($ENV{TRAVIS})
Expand Down
2 changes: 1 addition & 1 deletion scripts/cmake/ClangSanitizer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ if(OGS_UNDEFINED_BEHAVIOR_SANITIZER)
endif()

if(DEFINED SANITIZE_FLAG_VALUE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${SANITIZE_FLAG_VALUE} ${ADDITIONAL_FLAGS}")
add_compile_options(-fsanitize=${SANITIZE_FLAG_VALUE} ${ADDITIONAL_FLAGS})
endif()
192 changes: 78 additions & 114 deletions scripts/cmake/CompilerSetup.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
include(ResetConfigurations) # To Debug, Release, RelWithDebInfo
include(DisableCompilerFlag)
include(MSVCMultipleProcessCompile) # /MP switch (multi processor) for VS
set(CMAKE_OSX_ARCHITECTURES "x86_64")

# C++ standard setup
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -16,7 +11,6 @@ if(OGS_USE_PCH)
endif()

# Set compiler helper variables

if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
set(COMPILER_IS_CLANG TRUE CACHE INTERNAL "")
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
Expand All @@ -36,129 +30,99 @@ if(BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()

if(OGS_ENABLE_AVX2)
set(CPU_FLAGS "-mavx2 -march=core-avx2")
elseif(OGS_CPU_ARCHITECTURE STREQUAL "generic")
set(CPU_FLAGS "-mtune=generic")
else()
set(CPU_FLAGS "-march=${OGS_CPU_ARCHITECTURE}")
endif()

### GNU C/CXX compiler
if(COMPILER_IS_GCC)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")
message(FATAL_ERROR "GCC minimum required version is 4.9! You are \
using ${CMAKE_CXX_COMPILER_VERSION}.")
endif()
### GNU-like compiler
if(COMPILER_IS_GCC OR COMPILER_IS_CLANG OR COMPILER_IS_INTEL)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Set GCC release flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
else()
message(STATUS "Set release compiler flags")
add_compile_options(-O3)
elseif(NOT STL_NO_DEBUG)
# Enable assertions in STL in debug mode.
if(NOT STL_NO_DEBUG)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} \
-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_ASSERT \
-D_GLIBCXX_DEBUG_PEDASSERT -D_GLIBCXX_DEBUG_VERIFY")
endif()
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPU_FLAGS} -Wno-deprecated -Wall \
-Wextra -fext-numeric-literals")
endif() # COMPILER_IS_GCC

### Clang
if(COMPILER_IS_CLANG)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5")
message(FATAL_ERROR "Aborting: Clang 3.5 is required! Found version \
${CMAKE_CXX_COMPILER_VERSION}")
add_compile_options(
-D_GLIBCXX_DEBUG
-D_GLIBCXX_DEBUG_ASSERT
-D_GLIBCXX_DEBUG_PEDASSERT
-D_GLIBCXX_DEBUG_VERIFY
)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPU_FLAGS} -Wall \
-Wno-c++98-compat-pedantic")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# Enable assertions in STL in debug mode.
if(NOT STL_NO_DEBUG)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} \
-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_ASSERT \
-D_GLIBCXX_DEBUG_PEDASSERT -D_GLIBCXX_DEBUG_VERIFY")
add_compile_options(
-Wall
-Wextra
-Wno-c++98-compat-pedantic
-DOPENMP_LOOP_TYPE=unsigned
)

# Profiling
if(OGS_PROFILE)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
message(STATUS "When using profiling you should set CMAKE_BUILD_TYPE \
to Release.")
endif()
set(PROFILE_FLAGS "-pg -fno-omit-frame-pointer -O2 -DNDEBUG")
# clang compiler does not know the following flags
if(NOT COMPILER_IS_CLANG)
set(PROFILE_FLAGS "${PROFILE_FLAGS} -fno-inline-functions-called-once \
-fno-optimize-sibling-calls")
endif()
add_compile_options(${PROFILE_ARGS})
endif()

include(ClangSanitizer)
endif() # COMPILER_IS_CLANG

### Intel compiler
if(COMPILER_IS_INTEL)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Set Intel release flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
if(OGS_ENABLE_AVX2)
set(CPU_FLAGS "-mavx2 -march=core-avx2")
elseif(OGS_CPU_ARCHITECTURE STREQUAL "generic")
set(CPU_FLAGS "-mtune=generic")
else()
set(CPU_FLAGS "-march=${OGS_CPU_ARCHITECTURE}")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHOST")
endif() # COMPILER_IS_INTEL

# Profiling
if(OGS_PROFILE)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
message(STATUS "When using profiling you should set CMAKE_BUILD_TYPE \
to Release.")
endif()
set(PROFILE_FLAGS "-pg -fno-omit-frame-pointer -O2 -DNDEBUG")
# clang compiler does not know the following flags
if(NOT COMPILER_IS_CLANG)
set(PROFILE_FLAGS "${PROFILE_FLAGS} -fno-inline-functions-called-once \
-fno-optimize-sibling-calls")
if(COMPILER_IS_GCC)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")
message(FATAL_ERROR "GCC minimum required version is 4.9! You are \
using ${CMAKE_CXX_COMPILER_VERSION}.")
endif()
add_compile_options(-fext-numeric-literals)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PROFILE_FLAGS}")
endif()

### Windows
if(WIN32)
## For Visual Studio compiler
if(MSVC)
if(OGS_CPU_ARCHITECTURE STREQUAL "native")
set(CPU_FLAGS "/favor:blend")
else()
set(CPU_FLAGS "/favor:${OGS_CPU_ARCHITECTURE}")
if(COMPILER_IS_CLANG)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5")
message(FATAL_ERROR "Aborting: Clang 3.5 is required! Found version \
${CMAKE_CXX_COMPILER_VERSION}")
endif()
if(OGS_ENABLE_AVX2)
set(CPU_FLAGS "${CPU_FLAGS} /arch:AVX2")
endif()
add_definitions(
-D_CRT_SECURE_NO_WARNINGS
-D_CRT_NONSTDC_NO_WARNINGS
-D_CRT_XNONSTDC_NO_WARNINGS
-D__restrict__=__restrict # this fixes #5
# This fixes compile errors with
# std::numeric_limits<T>::min() / max()
-DNOMINMAX
)
# Sets warning level 3 and ignores some warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPU_FLAGS} /W3 /wd4290 \
/wd4267 /wd4996 /bigobj")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} \
/ZI /Od /Ob0")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /ignore:4099")
include(ClangSanitizer)
endif()

DisableCompilerFlag(DEBUG /RTC1)
# cygwin
else()
if(CMAKE_CROSSCOMPILING)
message(STATUS "Crosscompiling for Windows with MinGW.")
else()
message(STATUS "Might be GCC under cygwin.")
endif()
if(COMPILER_IS_INTEL)
# Use highest instruction set available on the compilation host processor
add_compile_options(-xHOST)
endif()
endif()

# Missing OpenMP 3.0 implementation fix for Windows, this fixes #6
if(MSVC)
add_definitions(-DOPENMP_LOOP_TYPE=int)
else()
add_definitions(-DOPENMP_LOOP_TYPE=unsigned)
if(OGS_CPU_ARCHITECTURE STREQUAL "native")
set(CPU_FLAGS "/favor:blend")
else()
set(CPU_FLAGS "/favor:${OGS_CPU_ARCHITECTURE}")
endif()
if(OGS_ENABLE_AVX2)
set(CPU_FLAGS "${CPU_FLAGS} /arch:AVX2")
endif()
add_compile_options(
/MP # multi-core compilation
/W3
/wd4290 /wd4267 /wd4996
/bigobj
-DOPENMP_LOOP_TYPE=int # Missing OpenMP 3.0 implementation fix for Windows, this fixes #6
-D_CRT_SECURE_NO_WARNINGS
-D_CRT_NONSTDC_NO_WARNINGS
-D_CRT_XNONSTDC_NO_WARNINGS
-D__restrict__=__restrict # this fixes #5
# This fixes compile errors with
# std::numeric_limits<T>::min() / max()
-DNOMINMAX
)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4099")
endif()

# Set additional user-given compiler flags. The given flags must follow the
# preceding cxx flags definition in order to override earlier flags, e.g. for
# optimization.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OGS_CXX_FLAGS}")

# Copy CXX to C flags. To have these flags in C libraries (e.g. metis) too.
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
add_compile_options(
${OGS_CXX_FLAGS} # user-given, CMake-option
${CPU_FLAGS}
)
7 changes: 2 additions & 5 deletions scripts/cmake/Find.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ if(OGS_NO_EXTERNAL_LIBS)
return()
endif() # OGS_NO_EXTERNAL_LIBS

find_package(OpenMP QUIET)
find_package(OpenMP)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
message(STATUS "OpenMP enabled.")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

find_package(Metis QUIET)
Expand All @@ -103,9 +103,6 @@ if(OGS_BUILD_GUI)
endif()
find_package(Qt5 5.2 REQUIRED ${QT_MODULES})
cmake_policy(SET CMP0020 NEW)
set(CMAKE_AUTOMOC TRUE)
set(CMAKE_AUTOUIC TRUE)
set(CMAKE_AUTORCC TRUE)
if(CMAKE_CROSSCOMPILING)
find_package(PkgConfig REQUIRED)
pkg_check_modules(QT_XML_DEPS REQUIRED Xml)
Expand Down