-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split CMake project into library and executable targets
This CMake project only had one executable target, so there was no way to compile it as a library. This commit splits the executable target into two library targets using the [shared static starter][1] repo by Alex Reinking for reference. [1]: https://github.com/alexreinking/SharedStaticStarter
- Loading branch information
Showing
7 changed files
with
146 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,50 @@ | ||
project(jpge) | ||
|
||
cmake_minimum_required(VERSION 3.0) | ||
option(BUILD_X64 "build 64-bit" TRUE) | ||
option(STATIC "static linking" FALSE) | ||
|
||
message("Initial BUILD_X64=${BUILD_X64}") | ||
message("Initial CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") | ||
|
||
if( NOT CMAKE_BUILD_TYPE ) | ||
set( CMAKE_BUILD_TYPE Release ) | ||
endif( NOT CMAKE_BUILD_TYPE ) | ||
|
||
message( ${PROJECT_NAME} " build type: " ${CMAKE_BUILD_TYPE} ) | ||
|
||
if (BUILD_X64) | ||
message("Building 64-bit") | ||
else() | ||
message("Building 32-bit") | ||
endif(BUILD_X64) | ||
|
||
if (NOT MSVC) | ||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") | ||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") | ||
|
||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") | ||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") | ||
|
||
set(CMAKE_CXX_FLAGS -std=c++11) | ||
set(GCC_COMPILE_FLAGS "-fno-strict-aliasing -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -Wall -Wextra") | ||
|
||
if (NOT BUILD_X64) | ||
set(GCC_COMPILE_FLAGS "${GCC_COMPILE_FLAGS} -m32") | ||
endif() | ||
|
||
if (STATIC) | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS} -static-libgcc -static-libstdc++ -static") | ||
else() | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS} -Wl,-rpath .") | ||
endif(STATIC) | ||
|
||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COMPILE_FLAGS}") | ||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${GCC_COMPILE_FLAGS}") | ||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${GCC_COMPILE_FLAGS} -D_DEBUG") | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMPILE_FLAGS}") | ||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${GCC_COMPILE_FLAGS}") | ||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${GCC_COMPILE_FLAGS} -D_DEBUG") | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
project(jpge LANGUAGES CXX) | ||
|
||
if(NOT MSVC) | ||
set_property(GLOBAL PROPERTY CXX_STANDARD 11) | ||
|
||
add_compile_options( | ||
-Wall | ||
-Wextra | ||
-fno-strict-aliasing | ||
) | ||
|
||
add_compile_definitions( | ||
_LARGEFILE64_SOURCE=1 | ||
_FILE_OFFSET_BITS=64 | ||
) | ||
|
||
if(MINGW) | ||
add_compile_definitions( | ||
WIN32 | ||
) | ||
endif() | ||
endif() | ||
|
||
set(BASISU_SRC_LIST ${COMMON_SRC_LIST} | ||
jpgd.cpp | ||
jpge.cpp | ||
tga2jpg.cpp | ||
timer.cpp | ||
) | ||
|
||
set(BIN_DIRECTORY "bin") | ||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${BIN_DIRECTORY}) | ||
|
||
add_executable(jpge ${BASISU_SRC_LIST}) | ||
|
||
install(TARGETS jpge DESTINATION bin) | ||
|
||
# JPEG decoder | ||
add_library(jpgd jpgd.cpp) | ||
add_library(jpge::jpgd ALIAS jpgd) | ||
target_include_directories(jpgd | ||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
# JPEG encoder (compressor) | ||
add_library(jpge jpge.cpp) | ||
add_library(jpge::jpge ALIAS jpge) | ||
target_include_directories(jpge | ||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
add_executable(tga2jpg tga2jpg.cpp timer.cpp) | ||
target_link_libraries(tga2jpg PRIVATE jpgd jpge) | ||
|
||
string(COMPARE EQUAL | ||
"${CMAKE_SOURCE_DIR}" | ||
"${CMAKE_CURRENT_SOURCE_DIR}" | ||
is_top_level) | ||
option(jpge_INCLUDE_PACKAGING "Package jpge" ${is_top_level}) | ||
if(jpge_INCLUDE_PACKAGING) | ||
add_subdirectory(cmake/packaging) | ||
endif() |
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,35 @@ | ||
include(GNUInstallDirs) | ||
|
||
if(NOT DEFINED jpge_INSTALL_CMAKEDIR) | ||
set(jpge_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/jpge" | ||
CACHE STRING "Path to jpge CMake modules") | ||
endif() | ||
|
||
install(TARGETS jpgd jpge EXPORT jpge_Targets | ||
ARCHIVE COMPONENT jpge_Development | ||
LIBRARY COMPONENT jpge_Runtime | ||
RUNTIME COMPONENT jpge_Runtime | ||
INCLUDES DIRECTORY "${CMAKE_INSTALL_INCLUDEDIR}") | ||
install(DIRECTORY "${jpge_SOURCE_DIR}/include/" | ||
TYPE INCLUDE | ||
COMPONENT jpge_Development) | ||
install(TARGETS tga2jpg RUNTIME COMPONENT jpge_Runtime) | ||
|
||
if(BUILD_SHARED_LIBS) | ||
set(type shared) | ||
else() | ||
set(type static) | ||
endif() | ||
|
||
install(EXPORT jpge_Targets | ||
DESTINATION "${jpge_INSTALL_CMAKEDIR}" | ||
NAMESPACE jpge:: | ||
FILE jpge-${type}-targets.cmake | ||
COMPONENT jpge_Development) | ||
|
||
install(FILES | ||
jpgeConfig.cmake | ||
DESTINATION "${jpge_INSTALL_CMAKEDIR}" | ||
COMPONENT jpge_Development) | ||
|
||
include(CPack) |
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,57 @@ | ||
cmake_minimum_required(VERSION 3.19) | ||
|
||
set(jpge_known_comps static shared) | ||
set(jpge_comp_static NO) | ||
set(jpge_comp_shared NO) | ||
foreach (jpge_comp IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS) | ||
if (jpge_comp IN_LIST jpge_known_comps) | ||
set(jpge_comp_${jpge_comp} YES) | ||
else () | ||
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE | ||
"jpge does not recognize component `${jpge_comp}`.") | ||
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) | ||
return() | ||
endif () | ||
endforeach () | ||
|
||
if (jpge_comp_static AND jpge_comp_shared) | ||
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE | ||
"jpge `static` and `shared` components are mutually exclusive.") | ||
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) | ||
return() | ||
endif () | ||
|
||
set(jpge_static_targets "${CMAKE_CURRENT_LIST_DIR}/jpge-static-targets.cmake") | ||
set(jpge_shared_targets "${CMAKE_CURRENT_LIST_DIR}/jpge-shared-targets.cmake") | ||
|
||
macro(jpge_load_targets type) | ||
if (NOT EXISTS "${jpge_${type}_targets}") | ||
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE | ||
"jpge `${type}` libraries were requested but not found.") | ||
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) | ||
return() | ||
endif () | ||
include("${jpge_${type}_targets}") | ||
endmacro() | ||
|
||
if (jpge_comp_static) | ||
jpge_load_targets(static) | ||
elseif (jpge_comp_shared) | ||
jpge_load_targets(shared) | ||
elseif (DEFINED jpge_SHARED_LIBS AND jpge_SHARED_LIBS) | ||
jpge_load_targets(shared) | ||
elseif (DEFINED jpge_SHARED_LIBS AND NOT jpge_SHARED_LIBS) | ||
jpge_load_targets(static) | ||
elseif (BUILD_SHARED_LIBS) | ||
if (EXISTS "${jpge_shared_targets}") | ||
jpge_load_targets(shared) | ||
else () | ||
jpge_load_targets(static) | ||
endif () | ||
else () | ||
if (EXISTS "${jpge_static_targets}") | ||
jpge_load_targets(static) | ||
else () | ||
jpge_load_targets(shared) | ||
endif () | ||
endif () |
File renamed without changes.
File renamed without changes.
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