-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated cmake to install package and make config
- Loading branch information
Showing
3 changed files
with
145 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@PACKAGE_INIT@ | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/OASValidatorTargets.cmake") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# cmake/SetCompilerFlags.cmake | ||
|
||
# Function to set compiler-specific flags | ||
function(set_compiler_flags target) | ||
if (POLICY CMP0025) | ||
# detect Apple's Clang | ||
cmake_policy(SET CMP0025 NEW) | ||
endif () | ||
if (POLICY CMP0054) | ||
cmake_policy(SET CMP0054 NEW) | ||
endif () | ||
if (POLICY CMP0091) | ||
cmake_policy(SET CMP0091 NEW) | ||
endif () | ||
|
||
find_program(CCACHE_FOUND ccache) | ||
if (CCACHE_FOUND) | ||
message(STATUS "Using ccache") | ||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) | ||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) | ||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
target_compile_options(${target} PRIVATE -Qunused-arguments -fcolor-diagnostics) | ||
endif () | ||
endif () | ||
|
||
############################# Compiler-specific settings ############################# | ||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
message(STATUS "Using GNU compiler") | ||
if (NOT CMAKE_CROSSCOMPILING) | ||
message(STATUS "Using native CPU optimizations") | ||
target_compile_options(${target} PRIVATE -march=native) | ||
endif () | ||
target_compile_options(${target} PRIVATE -Wall -Wextra -Werror -Weffc++ -Wswitch-default -Wfloat-equal -Wconversion -Wsign-conversion) | ||
if (OASVALIDATOR_BUILD_CXX11 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7.0") | ||
target_compile_options(${target} PRIVATE -std=c++0x) | ||
endif () | ||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
message(STATUS "Using Clang compiler") | ||
if (NOT CMAKE_CROSSCOMPILING) | ||
message(STATUS "Using native CPU optimizations") | ||
target_compile_options(${target} PRIVATE -march=native) | ||
endif () | ||
target_compile_options(${target} PRIVATE -Wall -Wextra -Werror -Wno-missing-field-initializers -Weffc++ -Wswitch-default -Wfloat-equal -Wconversion -Wimplicit-fallthrough) | ||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") | ||
message(STATUS "Using MSVC compiler") | ||
target_compile_definitions(${target} PRIVATE -D_CRT_SECURE_NO_WARNINGS=1 -DNOMINMAX) | ||
target_compile_options(${target} PRIVATE /EHsc /WX) | ||
if (OASVALIDATOR_BUILD_CXX11 AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.10") | ||
target_compile_options(${target} PRIVATE /std:c++11) | ||
elseif (OASVALIDATOR_BUILD_CXX17) | ||
target_compile_options(${target} PRIVATE /std:c++17) | ||
endif () | ||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL") | ||
message(STATUS "Using XL compiler") | ||
target_compile_options(${target} PRIVATE -qarch=auto) | ||
endif () | ||
|
||
# if release build, add extra optimization flags | ||
if (CMAKE_BUILD_TYPE STREQUAL "Release") | ||
message(STATUS "Adding extra optimization flags for release build") | ||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
target_compile_options(${target} PRIVATE -O3 -ffast-math -funroll-loops -fomit-frame-pointer -DNDEBUG -fno-strict-aliasing -fvisibility-inlines-hidden) | ||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") | ||
target_compile_options(${target} PRIVATE /Ox /Ob2 /Oi /Ot /Oy /GL /fp:fast /GS- /Gy /DNDEBUG) | ||
endif () | ||
endif () | ||
endfunction() |