Skip to content
Permalink
Browse files

CMakeLists: modernize to 3.5.x

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
  • Loading branch information...
tycho committed May 24, 2018
1 parent 246e12a commit 4f16ee8084b1069a85fa022a6aa81b850c325974
@@ -1,132 +1,39 @@
cmake_minimum_required (VERSION 2.8.13)

if(COMMAND cmake_policy)
cmake_policy(VERSION 2.8.13)
endif(COMMAND cmake_policy)

project (CrissCross)

set(CMAKE_BUILD_TYPE CrissCrossDefaultBuildType)

IF(CMAKE_COMPILER_IS_GNUCXX)
EXEC_PROGRAM(
${CMAKE_CXX_COMPILER}
ARGS -dumpversion
OUTPUT_VARIABLE _compiler_output)
STRING(REGEX REPLACE ".*([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1"
gcc_compiler_version ${_compiler_output})
MESSAGE("GCC Version: ${gcc_compiler_version}")
IF(gcc_compiler_version MATCHES "4\\.[2-9]\\.[0-9]")
MESSAGE("Enabling OpenMP")
SET(GCCOpenMPSupport TRUE)
ENDIF(gcc_compiler_version MATCHES "4\\.[2-9]\\.[0-9]")
IF(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]")
MESSAGE("Enabling precompiled headers")
SET(PCHSupport_FOUND TRUE)
ELSE(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]")
IF(gcc_compiler_version MATCHES "3\\.4\\.[0-9]")
MESSAGE("Enabling precompiled headers")
SET(PCHSupport_FOUND TRUE)
ENDIF(gcc_compiler_version MATCHES "3\\.4\\.[0-9]")
ENDIF(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)

MACRO(ADD_PRECOMPILED_HEADER _targetName _header _source)
IF(MSVC)
STRING(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" _headerName "${_header}")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Yu\"${_headerName}\"")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Yu\"${_headerName}\"")
GET_FILENAME_COMPONENT(_sourceFile ${_source} NAME)
set_source_files_properties("${_sourceFile}"
COMPILE_FLAGS "/Yc\"${_headerName}\""
)
ENDIF(MSVC)
IF(CMAKE_COMPILER_IS_GNUCXX AND NOT XCODE AND PCHSupport_FOUND)
IF(NOT CMAKE_BUILD_TYPE)
MESSAGE(FATAL_ERROR
"This is the ADD_PRECOMPILED_HEADER macro. "
"You must set CMAKE_BUILD_TYPE!"
)
ENDIF(NOT CMAKE_BUILD_TYPE)

GET_FILENAME_COMPONENT(_name ${_header} NAME)
GET_FILENAME_COMPONENT(_path ${_header} PATH)
SET(_outdir "${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch")
SET(_output "${_outdir}/${CMAKE_BUILD_TYPE}.c++")

ADD_CUSTOM_COMMAND(
OUTPUT ${_outdir}
COMMAND mkdir -p ${_outdir} # TODO: {CMAKE_COMMAND} -E ...
)
#MAKE_DIRECTORY(${_outdir})

STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name)
SET(_compile_FLAGS ${${_flags_var_name}})
GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES)

SET(_CMAKE_CURRENT_BINARY_DIR_included_before_path FALSE)
FOREACH(item ${_directory_flags})
IF(${item} STREQUAL ${_path} AND NOT _CMAKE_CURRENT_BINARY_DIR_included_before_path )
MESSAGE(FATAL_ERROR
"This is the ADD_PRECOMPILED_HEADER macro. "
"CMAKE_CURRENT_BINARY_DIR has to mentioned at INCLUDE_DIRECTORIES's argument list before ${_path}, where ${_name} is located"
)
ENDIF(${item} STREQUAL ${_path} AND NOT _CMAKE_CURRENT_BINARY_DIR_included_before_path )

IF(${item} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
SET(_CMAKE_CURRENT_BINARY_DIR_included_before_path TRUE)
ENDIF(${item} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})

LIST(APPEND _compile_FLAGS "-I${item}")
ENDFOREACH(item)

GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
LIST(APPEND _compile_FLAGS ${_directory_flags})
LIST(APPEND _compile_FLAGS ${CMAKE_CXX_FLAGS} )

SEPARATE_ARGUMENTS(_compile_FLAGS)
#MESSAGE("_compiler_FLAGS: ${_compiler_FLAGS}")
#message(${_compile_FLAGS} )
#message("COMMAND ${CMAKE_CXX_COMPILER} ${_compile_FLAGS} -x c++-header -o ${_output} ${_header}")

ADD_CUSTOM_COMMAND(
OUTPUT ${_output}
COMMAND ${CMAKE_CXX_COMPILER}
${_compile_FLAGS}
-x c++-header
-o ${_output}
${_header}
DEPENDS ${_header} ${_outdir}
)
ADD_CUSTOM_TARGET(${_targetName}_gch
DEPENDS ${_output}
)
ADD_DEPENDENCIES(${_targetName} ${_targetName}_gch)
ADD_DEPENDENCIES(${_targetName}_gch BuildNumber)
SET_TARGET_PROPERTIES(${_targetName}
PROPERTIES
COMPILE_FLAGS "-include ${_header} -Winvalid-pch"
)
ENDIF(CMAKE_COMPILER_IS_GNUCXX AND NOT XCODE AND PCHSupport_FOUND)
ENDMACRO(ADD_PRECOMPILED_HEADER)

MACRO(ADD_FLAG where flag)
SET(${where} "${flag} ${${where}}")
ENDMACRO(ADD_FLAG)

if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=gnu++98 -fno-common -fno-strict-aliasing -fno-rtti -fno-exceptions -Wall -Wundef -Wno-long-long -pedantic -I/usr/local/include")
if(GCCOpenMPSupport)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
endif(GCCOpenMPSupport)
if(NOT CYGWIN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
if(NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
endif(NOT APPLE)
endif(NOT CYGWIN)
endif(CMAKE_COMPILER_IS_GNUCXX)
cmake_minimum_required (VERSION 3.5)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

project (CrissCross CXX)

option(USE_OPENMP "Build with OpenMP support" ON)

include(CheckCXXCompilerFlag)

set(CC_COMMON_FLAGS
-fno-strict-aliasing
-fvisibility=hidden
-rdynamic
-Wall
-Wundef
-Wno-long-long
-pedantic)

set(CC_CXX_FLAGS
-Wno-non-virtual-dtor
-Wno-reorder
-fno-exceptions
-fno-rtti
-fvisibility-inlines-hidden)

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU"
OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
foreach(FLAG ${CC_COMMON_FLAGS} ${CC_CXX_FLAGS})
string(MAKE_C_IDENTIFIER ${FLAG} FLAG_ID)
check_cxx_compiler_flag(${FLAG} ${FLAG_ID}_TEST)
if(${FLAG_ID}_TEST)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${FLAG}>)
endif()
endforeach()
endif()

# settings for Microsoft Visual C
IF(MSVC)
@@ -167,12 +74,6 @@ IF(MSVC)
ENDIF(NOT WITH_SHARED_LIBS)
ENDIF(MSVC)

include_directories (
${CrissCross_BINARY_DIR}
${CrissCross_BINARY_DIR}/source
${CrissCross_SOURCE_DIR}/source
.)

add_subdirectory (source)
add_subdirectory (TestSuite)
add_subdirectory (examples)
@@ -1,4 +1,31 @@
add_executable(TestSuite avltree.cpp backtrace.cpp compare.cpp darray.cpp datatypes.cpp dstack.cpp hashtable.cpp header.cpp llist.cpp main.cpp md4.cpp md5.cpp rbtree.cpp sanity.cpp sha1.cpp sha256.cpp sha512.cpp sort.cpp splaytree.cpp stltree.cpp stopwatch.cpp stree.cpp testutils.cpp tiger.cpp)
add_precompiled_header(TestSuite ${CMAKE_CURRENT_SOURCE_DIR}/header.h ${CMAKE_CURRENT_SOURCE_DIR}/header.cpp)
add_executable(TestSuite
avltree.cpp
backtrace.cpp
compare.cpp
darray.cpp
datatypes.cpp
dstack.cpp
hashtable.cpp
header.cpp
llist.cpp
main.cpp
md4.cpp
md5.cpp
rbtree.cpp
sanity.cpp
sha1.cpp
sha256.cpp
sha512.cpp
sort.cpp
splaytree.cpp
stltree.cpp
stopwatch.cpp
stree.cpp
testutils.cpp
tiger.cpp
)

target_link_libraries (TestSuite CrissCross)
target_include_directories(TestSuite
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(TestSuite CrissCross)
@@ -1,4 +1,7 @@
add_executable(CPSAT header.cpp main.cpp rijndael-alg-fst.cpp rijndael.cpp)
add_precompiled_header(CPSAT ${CMAKE_CURRENT_SOURCE_DIR}/header.h ${CMAKE_CURRENT_SOURCE_DIR}/header.cpp)
add_executable(CPSAT
header.cpp
main.cpp
rijndael-alg-fst.cpp
rijndael.cpp)

target_link_libraries (CPSAT CrissCross)
target_link_libraries(CPSAT CrissCross)
@@ -1,4 +1,8 @@
add_executable(CheckMark adler32.cpp crc32.cpp header.cpp main.cpp random.cpp)
add_precompiled_header(CheckMark ${CMAKE_CURRENT_SOURCE_DIR}/header.h ${CMAKE_CURRENT_SOURCE_DIR}/header.cpp)
add_executable(CheckMark
adler32.cpp
crc32.cpp
header.cpp
main.cpp
random.cpp)

target_link_libraries (CheckMark CrissCross)
target_link_libraries(CheckMark CrissCross)
@@ -1,4 +1,5 @@
add_executable(EmptyProject header.cpp main.cpp)
add_precompiled_header(EmptyProject ${CMAKE_CURRENT_SOURCE_DIR}/header.h ${CMAKE_CURRENT_SOURCE_DIR}/header.cpp)
add_executable(EmptyProject
header.cpp
main.cpp)

target_link_libraries (EmptyProject CrissCross)
target_link_libraries(EmptyProject CrissCross)
@@ -1,4 +1,5 @@
add_executable(GenPrime header.cpp main.cpp)
add_precompiled_header(GenPrime ${CMAKE_CURRENT_SOURCE_DIR}/header.h ${CMAKE_CURRENT_SOURCE_DIR}/header.cpp)
add_executable(GenPrime
header.cpp
main.cpp)

target_link_libraries (GenPrime CrissCross)
target_link_libraries(GenPrime CrissCross)
@@ -1,4 +1,5 @@
add_executable(SortBenchmark header.cpp main.cpp)
add_precompiled_header(SortBenchmark ${CMAKE_CURRENT_SOURCE_DIR}/header.h ${CMAKE_CURRENT_SOURCE_DIR}/header.cpp)
add_executable(SortBenchmark
header.cpp
main.cpp)

target_link_libraries (SortBenchmark CrissCross)
target_link_libraries(SortBenchmark CrissCross)
@@ -1,4 +1,5 @@
add_executable(TreeBenchmark header.cpp main.cpp)
add_precompiled_header(TreeBenchmark ${CMAKE_CURRENT_SOURCE_DIR}/header.h ${CMAKE_CURRENT_SOURCE_DIR}/header.cpp)
add_executable(TreeBenchmark
header.cpp
main.cpp)

target_link_libraries (TreeBenchmark CrissCross)
target_link_libraries(TreeBenchmark CrissCross)
@@ -1,23 +1,67 @@
find_package(Threads REQUIRED)
if(USE_OPENMP)
find_package(OpenMP)
endif()

if(WIN32 AND MSVC)
add_custom_command(
OUTPUT ${CrissCross_BINARY_DIR}/source/crisscross/build_number.h
COMMAND "${CrissCross_SOURCE_DIR}/tools/gen_buildnum_h_helper.cmd" "${CrissCross_SOURCE_DIR}"
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/build_number.h
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/../tools/gen_buildnum_h_helper.cmd" "${CMAKE_CURRENT_BINARY_DIR}"
)
else(WIN32 AND MSVC)
add_custom_command(
OUTPUT ${CrissCross_BINARY_DIR}/source/crisscross/build_number.h
COMMAND "${CrissCross_SOURCE_DIR}/tools/gen_buildnum_h.pl" "${CrissCross_BINARY_DIR}/source/crisscross/build_number.h"
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/build_number.h
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/../tools/gen_buildnum_h.pl" "${CMAKE_CURRENT_BINARY_DIR}/build_number.h"
)
endif(WIN32 AND MSVC)

add_custom_target(BuildNumber DEPENDS ${CrissCross_BINARY_DIR}/source/crisscross/build_number.h)
add_library(CrissCross compare.cpp console.cpp core_io_reader.cpp core_io_writer.cpp debug.cpp error.cpp filesystem.cpp filereader.cpp filewriter.cpp md4.cpp md5.cpp mutex.cpp sha1.cpp sha256.cpp sha512.cpp stopwatch.cpp string_utils.cpp system.cpp tiger.cpp universal_include.cpp version.cpp zombiehunter.cpp)
add_precompiled_header(CrissCross ${CMAKE_CURRENT_SOURCE_DIR}/crisscross/universal_include.h ${CMAKE_CURRENT_SOURCE_DIR}/universal_include.cpp)
add_custom_target(BuildNumber
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/build_number.h)

add_library(CrissCross STATIC
compare.cpp
console.cpp
core_io_reader.cpp
core_io_writer.cpp
debug.cpp
error.cpp
filesystem.cpp
filereader.cpp
filewriter.cpp
md4.cpp
md5.cpp
mutex.cpp
sha1.cpp
sha256.cpp
sha512.cpp
stopwatch.cpp
string_utils.cpp
system.cpp
tiger.cpp
universal_include.cpp
version.cpp
zombiehunter.cpp
)

if(OPENMP_CXX_FOUND)
target_compile_options(CrissCross PUBLIC
${OpenMP_CXX_FLAGS})
target_link_libraries(CrissCross PUBLIC
${OpenMP_CXX_FLAGS})
endif()

set_target_properties(CrissCross PROPERTIES CXX_STANDARD 11)

target_include_directories(CrissCross PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_include_directories(CrissCross PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
)

add_dependencies(CrissCross BuildNumber)

install(TARGETS CrissCross ARCHIVE DESTINATION lib)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/crisscross/ DESTINATION include/crisscross)

if(NOT WIN32)
target_link_libraries(CrissCross pthread)
ENDIF(NOT WIN32)
target_link_libraries(CrissCross PUBLIC Threads::Threads)

0 comments on commit 4f16ee8

Please sign in to comment.
You can’t perform that action at this time.