Last active
July 2, 2019 10:47
-
-
Save SuperFola/56fc3d89cfc7c83cc8efef59eeba407f to your computer and use it in GitHub Desktop.
a default cmakelists for... anything (nearly)
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
cmake_minimum_required(VERSION 3.8) # using the latest version atm | |
project(project_name) | |
set(LIB_NAME lib_${PROJECT_NAME}) | |
if (CMAKE_BUILD_TYPE MATCHES Debug) | |
if (CMAKE_COMPILER_IS_GNUCXX) | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg -g -no-pie") | |
elseif (MSVC) | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MTd") | |
endif() | |
elseif (CMAKE_BUILD_TYPE MATCHES Release) | |
if (CMAKE_COMPILER_IS_GNUCXX) | |
set(CMAKE_CXX_FLAGS "-DNDEBUG -O4 -s") | |
elseif (MSVC) | |
set(CMAKE_CXX_FLAGS "/Ox /Ob2 /Oi /Ot /Oy /MT") | |
endif() | |
endif() | |
if (CMAKE_COMPILER_IS_GNUCXX) | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-rpath,/usr/local/lib") | |
endif() | |
configure_file( | |
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/Constants.hpp.in | |
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/Constants.hpp | |
) | |
# everything that will be used like this : #include <lib/file.hpp> | |
# ext/ | |
# lib/ | |
# file.hpp | |
include_directories( | |
${PROJECT_SOURCE_DIR}/ext # ext libs | |
${PROJECT_SOURCE_DIR}/include # includes for the project | |
) | |
# fetching all .cpp | |
file(GLOB_RECURSE SOURCE_FILES | |
${PROJECT_SOURCE_DIR}/src/*.cpp | |
# add this if there are .c/.cpp to compile in the ext folder | |
${PROJECT_SOURCE_DIR}/ext/*.cpp | |
${PROJECT_SOURCE_DIR}/ext/*.c | |
) | |
list(REMOVE_ITEM SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/main.cpp") | |
# the libs we need (example is for an opengl project) | |
set(ALL_LIBS glfw GL GLU X11 pthread Xrandr Xi dl) | |
set(LINUX_LIBS ${CMAKE_DL_LIBS}) | |
set(WINDOWS_LIBS list()) | |
add_library(${LIB_NAME} ${SOURCE_FILES}) | |
set_property(TARGET ${LIB_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) | |
add_executable(${PROJECT_NAME} ${Ark_SOURCE_DIR}/src/main.cpp) | |
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIB_NAME}) | |
if (UNIX OR LINUX) | |
target_link_libraries(${LIB_NAME} PUBLIC ${LINUX_LIBS}) | |
elseif (WIN32) | |
target_link_libraries(${LIB_NAME} PUBLIC ${WINDOWS_LIBS}) | |
endif() | |
target_link_libraries(${LIB_NAME} PUBLIC ${ALL_LIBS}) | |
set_target_properties( | |
${LIB_NAME} | |
PROPERTIES | |
CXX_STANDARD 17 | |
CXX_STANDARD_REQUIRED ON | |
CXX_EXTENSIONS OFF | |
) | |
set_target_properties( | |
${PROJECT_NAME} | |
PROPERTIES | |
CXX_STANDARD 17 | |
CXX_STANDARD_REQUIRED ON | |
CXX_EXTENSIONS OFF | |
) | |
install(TARGETS ${PROJECT_NAME} DESTINATION bin) | |
install(DIRECTORY ${PROJECT_SOURCE_DIR}/bin DESTINATION share/${PROJECT_NAME}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment