Skip to content

Commit 0d7b24d

Browse files
authored
Add mingw support (#147)
* Lowercase Windows include files to support minw@Linux * Add CELERO_COMPILE_FPIC to enable/desable fPIC (enabled by default) * Use CMake's CXX_STANDARD+CXX_EXTENSIONS to set c++ standard * Install implib+library in same directory - Add .dll to implib on MSVC, this suffix is already added on mingw
1 parent 0136154 commit 0d7b24d

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,29 @@
2424
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2)
2525

2626
macro(CeleroSetDefaultCompilerOptions)
27+
set_target_properties(${PROJECT_NAME} PROPERTIES
28+
POSITION_INDEPENDENT_CODE "${CELERO_COMPILE_PIC}"
29+
)
2730
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
2831
target_compile_options(${PROJECT_NAME} PRIVATE /D_VARIADIC_MAX=10 )
2932
target_compile_options(${PROJECT_NAME} PRIVATE /D_CRT_SECURE_NO_WARNINGS)
3033
target_compile_options(${PROJECT_NAME} PRIVATE /wd4251)
3134
target_compile_options(${PROJECT_NAME} PRIVATE /MP)
3235
target_compile_options(${PROJECT_NAME} PRIVATE /D_SCL_SECURE_NO_WARNINGS)
3336
target_compile_options(${PROJECT_NAME} PRIVATE /permissive-)
34-
target_compile_options(${PROJECT_NAME} PRIVATE /std:c++14)
3537

3638
if(CELERO_TREAT_WARNINGS_AS_ERRORS)
3739
target_compile_options(${PROJECT_NAME} PRIVATE /WX)
3840
endif()
41+
set_target_properties(${PROJECT_NAME} PROPERTIES
42+
ARCHIVE_OUTPUT_NAME "${PROJECT_NAME}.dll")
3943

4044
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
4145
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
42-
target_compile_options(${PROJECT_NAME} PRIVATE -fPIC)
43-
target_compile_options(${PROJECT_NAME} PRIVATE -std=c++14)
4446

4547
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
4648
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
47-
target_compile_options(${PROJECT_NAME} PRIVATE -Xclang -std=c++14)
49+
target_compile_options(${PROJECT_NAME} PRIVATE -Xclang)
4850
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-c++98-compat)
4951
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-c++98-compat-pedantic)
5052
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-reserved-id-macro)
@@ -53,17 +55,13 @@ macro(CeleroSetDefaultCompilerOptions)
5355
endif()
5456
else()
5557
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
56-
target_compile_options(${PROJECT_NAME} PRIVATE -fPIC)
57-
target_compile_options(${PROJECT_NAME} PRIVATE -std=c++14)
5858
if(CELERO_TREAT_WARNINGS_AS_ERRORS)
5959
target_compile_options(${PROJECT_NAME} PRIVATE -Werror)
6060
endif()
6161
endif()
6262

6363
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang)
6464
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
65-
target_compile_options(${PROJECT_NAME} PRIVATE -fPIC)
66-
target_compile_options(${PROJECT_NAME} PRIVATE -std=c++14)
6765

6866
if(CELERO_TREAT_WARNINGS_AS_ERRORS)
6967
target_compile_options(${PROJECT_NAME} PRIVATE -Werror)
@@ -83,6 +81,7 @@ include(CheckIncludeFile)
8381
#
8482

8583
option(CELERO_COMPILE_DYNAMIC_LIBRARIES "Set to ON to build Celero for dynamic linking. Use OFF for static." ON)
84+
option(CELERO_COMPILE_PIC "Set to ON to build Celero as a position-independent library." ON)
8685
option(CELERO_ENABLE_EXPERIMENTS "Set to ON to automatically build all examples." OFF)
8786
option(CELERO_ENABLE_FOLDERS "Enable to put Celero in its own solution folder under Visual Studio" ON)
8887
option(CELERO_ENABLE_TESTS "Enable building and running unit tests." OFF)
@@ -101,6 +100,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
101100
#
102101

103102
set(CMAKE_CXX_STANDARD 14)
103+
set(CMAKE_CXX_EXTENSIONS OFF)
104104

105105
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually d on windows")
106106
set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
@@ -176,9 +176,9 @@ target_sources(${PROJECT_NAME} PRIVATE
176176
src/Utilities.cpp
177177
)
178178

179-
if(MSVC)
179+
if(WIN32)
180180
set(SYSLIBS
181-
PowrProf.lib
181+
powrprof psapi
182182
)
183183
else()
184184
#pthread is required for std::thread to work.
@@ -204,7 +204,7 @@ install(TARGETS ${PROJECT_NAME}
204204
EXPORT ${PROJECT_NAME}-target
205205
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
206206
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
207-
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/static
207+
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
208208
)
209209

210210
install(DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX})

include/celero/Export.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
#else
2626
#ifdef WIN32
2727
#if defined CELERO_EXPORTS
28-
#define CELERO_EXPORT _declspec(dllexport)
29-
#define CELERO_EXPORT_C extern "C" _declspec(dllexport)
28+
#define CELERO_EXPORT __declspec(dllexport)
29+
#define CELERO_EXPORT_C extern "C" __declspec(dllexport)
3030
#else
31-
#define CELERO_EXPORT _declspec(dllimport)
32-
#define CELERO_EXPORT_C extern "C" _declspec(dllimport)
31+
#define CELERO_EXPORT __declspec(dllimport)
32+
#define CELERO_EXPORT_C extern "C" __declspec(dllimport)
3333
#endif
3434
#else
3535
#define CELERO_EXPORT

src/Console.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
using namespace celero;
2222

2323
#ifdef WIN32
24-
#include <Windows.h>
24+
#include <windows.h>
2525
#include <stdio.h>
2626
#else
2727
#include <iostream>

src/Exceptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <celero/TestFixture.h>
2323

2424
#ifdef WIN32
25-
#include <Windows.h>
25+
#include <windows.h>
2626
#endif // WIN32
2727

2828
#include <iomanip>

src/Memory.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
#include <celero/Memory.h>
2020
#include <sstream>
2121

22-
#ifdef WIN32
23-
#include <Windows.h>
22+
#ifdef _WIN32
23+
#include <windows.h>
2424

25-
#include <Psapi.h>
25+
#include <psapi.h>
2626
#elif defined(__APPLE__)
2727
#include <sys/param.h>
2828
#include <sys/sysctl.h>

src/Timer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <iostream>
2222

2323
#ifdef WIN32
24-
#include <Windows.h>
24+
#include <windows.h>
2525
LARGE_INTEGER QPCFrequency;
2626
#else
2727
#include <chrono>

src/Utilities.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
#include <celero/Utilities.h>
2121

2222
#ifdef WIN32
23-
#include <Windows.h>
23+
#include <windows.h>
2424

25-
#include <PowrProf.h>
25+
#include <powrprof.h>
2626
#endif
2727

2828
#ifdef max

0 commit comments

Comments
 (0)