# Apply optimizations flags to targets and correctly export interface # # Define two functions # # - spc_set_objlib_optimization_flags() # To apply the optimization flags to the object libraries # # - spc_set_target_optimization_flags() # To apply the optimization flags to the # # Gold Linker # ------------ # for LTO flags and compilation optimization include(gold_linker) if (USE_LD_GOLD) LIST(APPEND PUBLIC_FEATURES ${SPECMICP_GOLD_LINKER_FLAG}) endif() # OPENMP if (OpenMP_CXX_FOUND AND SPECMICP_USE_OPENMP) set(SPECMICP_HAVE_OPENMP ON) endif() # Native architecture # ------------------- include(CheckCXXCompilerFlag) if(${SPECMICP_OPTIMIZE_FOR_NATIVE}) CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) if(COMPILER_SUPPORTS_MARCH_NATIVE) LIST(APPEND PUBLIC_FEATURES -march=native) endif() endif() # Link time optimization # ---------------------- include(lto) if(HAVE_LTO_FLAG AND SPECMICP_LTO) LIST(APPEND PUBLIC_FEATURES ${SPECMICP_LTO_FLAGS}) endif() # functions definitions # --------------------- # Cache set(SPECMICP_PRIVATE_OPTIONS ${PRIVATE_FEATURES} CACHE INTERNAL "Specmicp public optimization options") set(SPECMICP_PUBLIC_OPTIONS ${PUBLIC_FEATURES} CACHE INTERNAL "Specmicp private optimization options") function(spc_set_objlib_optimization_flags target) # object libraries cannot directly link to other libraries, so we only add the flag LIST(APPEND PUBLIC_OPTIONS ${SPECMICP_PUBLIC_OPTIONS}) if (OpenMP_CXX_FOUND AND SPECMICP_USE_OPENMP) LIST(APPEND PUBLIC_OPTIONS ${OpenMP_CXX_FLAGS}) endif() target_compile_options(${target} PUBLIC ${PUBLIC_OPTIONS} PRIVATE ${SPECMICP_PRIVATE_OPTIONS}) endfunction(spc_set_objlib_optimization_flags target) function(spc_set_target_optimization_flags target) target_compile_options(${target} PUBLIC ${SPECMICP_PUBLIC_OPTIONS} PRIVATE ${SPECMICP_PRIVATE_OPTIONS}) if(OpenMP_CXX_FOUND AND SPECMICP_USE_OPENMP) target_link_libraries(${target} PUBLIC OpenMP::OpenMP_CXX) endif() endfunction(spc_set_target_optimization_flags target)