Skip to content

Commit

Permalink
Optimize cmake environment
Browse files Browse the repository at this point in the history
Remove cmake prefix to be able to use this as template for other projects
  • Loading branch information
florianbecker committed Jun 8, 2020
1 parent 583df24 commit 767ce4a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 46 deletions.
2 changes: 1 addition & 1 deletion cmake/clang_warnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# */

set(MCC_WARNING_FLAGS
set(WARNING_FLAGS

# From Xcode default project
# -Wno-sign-conversion
Expand Down
1 change: 0 additions & 1 deletion cmake/doxygen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ if (DOXYGEN_FOUND)
else (DOXYGEN_FOUND)
message("Doxygen need to be installed to generate the doxygen documentation")
endif (DOXYGEN_FOUND)

61 changes: 23 additions & 38 deletions cmake/env.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
#set(CMAKE_VERBOSE_MAKEFILE ON)

# Pathes
if(NOT MCC_DEV)
get_filename_component(MCC_DEV "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
if(NOT DEV)
get_filename_component(DEV "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
endif()

set(MCC_CMAKE ${MCC_DEV}/cmake)
set(CMAKE ${DEV}/cmake)

# Force C++17
set(CMAKE_CXX_STANDARD 17)
Expand All @@ -45,46 +45,31 @@ set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(USE_CLANG false)
if (CMAKE_CXX_COMPILER_ID MATCHES "[cC][lL][aA][nN][gG]") #Case insensitive match
set(USE_CLANG true)
else()
set(USE_CLANG false)
endif()

set(USE_GCC false)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(USE_GCC true)
else()
set(USE_GCC false)
endif()

# Warning flags
if(USE_CLANG)
include(${MCC_CMAKE}/clang_warnings.cmake)
# Case insensitive match
if(CMAKE_CXX_COMPILER_ID MATCHES "[cC][lL][aA][nN][gG]")
include(${CMAKE}/clang_warnings.cmake)

set(MCC_WARNING_FLAGS_SPACED "")
foreach(MCC_WARNING_FLAG ${MCC_WARNING_FLAGS})
set(MCC_WARNING_FLAGS_SPACED "${MCC_WARNING_FLAGS_SPACED} ${MCC_WARNING_FLAG}")
endforeach()
set(WARNING_FLAGS_SPACED "")
foreach(WARNING_FLAG ${WARNING_FLAGS})
set(WARNING_FLAGS_SPACED "${WARNING_FLAGS_SPACED} ${WARNING_FLAG}")
endforeach()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MCC_WARNING_FLAGS_SPACED}")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_SPACED}")

if(USE_GCC)
include(${MCC_CMAKE}/gcc_warnings.cmake)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
include(${CMAKE}/gcc_warnings.cmake)

set(MCC_WARNING_FLAGS_SPACED "")
foreach(MCC_WARNING_FLAG ${MCC_WARNING_FLAGS})
set(MCC_WARNING_FLAGS_SPACED "${MCC_WARNING_FLAGS_SPACED} ${MCC_WARNING_FLAG}")
endforeach()
set(WARNING_FLAGS_SPACED "")
foreach(WARNING_FLAG ${WARNING_FLAGS})
set(WARNING_FLAGS_SPACED "${WARNING_FLAGS_SPACED} ${WARNING_FLAG}")
endforeach()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MCC_WARNING_FLAGS_SPACED}")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_SPACED}")

if(MSVC)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Force to always compile with W4
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX")
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
Expand All @@ -97,7 +82,7 @@ add_compile_options("$<$<CONFIG:DEBUG>:-DDEBUG>")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Project modules/variables
set(CMAKE_MODULE_PATH ${MCC_CMAKE}/modules)
set(CMAKE_MODULE_PATH ${CMAKE}/modules)

# Includes
include(${MCC_CMAKE}/find_package.cmake)
include(${CMAKE}/find_package.cmake)
2 changes: 1 addition & 1 deletion cmake/gcc_warnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# */

set(MCC_WARNING_FLAGS
set(WARNING_FLAGS

# -Wno-unknown-pragmas
)
6 changes: 2 additions & 4 deletions examples/cpuinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@

project(cpuinfo)

include_directories(../../source)

add_executable(cpuinfo
add_executable(${PROJECT_NAME}
main.cpp
)

target_link_libraries(cpuinfo PRIVATE modern.cpp.core)
target_link_libraries(${PROJECT_NAME} PRIVATE modern.cpp.core)
4 changes: 3 additions & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

project(modern.cpp.core)

add_library(modern.cpp.core
add_library(${PROJECT_NAME}
../README.md
CPU.cpp
CPU.h
Expand All @@ -45,3 +45,5 @@ add_library(modern.cpp.core
templates/CSVWriter.h
templates/Timer.h
)

target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/templates)

0 comments on commit 767ce4a

Please sign in to comment.